$array = array(1, 2, 3, 4);
foreach ($array as &$valor) {
$valor = $valor * 2;
}
// $array ahora es array(2, 4, 6, 8)
unset($valor); // rompe la referencia con el último elemento
I found the above in the php documentation on how to do a foreach
and put: &$valor
, but I don't understand what the &
before variable is for
Can someone tell me what it means?
From the documentation at http://php.net/manual/es/control-structures.foreach.php
To reply to your comment.
&
indicates a value by reference (something similar to a pointer in other languages.Objects and references :