PDA

View Full Version : Param By Reference VARDUMP


sblommers
06-01-2010, 09:41 AM
$var=array('a'=>array(1,2,3),'b'=>array(4,5,6));

foreach ($var as &$sub) {
foreach ($sub as &$element) {
$element=$element+1;
}
}

var_dump($var);


OUTPUT APACHE+PHP
array(2) {
["a"]=>
array(3) {
[0]=>
int(2)
[1]=>
int(3)
[2]=>
int(4)
}
["b"]=>
&array(3) {
[0]=>
int(5)
[1]=>
int(6)
[2]=>
&int(7)
}
}

OUTPUT QUERCUS
array(2) {
["a"]=>
&array(3) {
[0]=>
&int(2)
[1]=>
&int(3)
[2]=>
&int(4)
}
["b"]=>
&array(3) {
[0]=>
&int(5)
[1]=>
&int(6)
[2]=>
&int(7)
}
}

Output seems incompatible. Doesn't this have any side-effects (reference) when going through another nested loop?

Sebastiaan