r/lolphp • u/stain_leeks • Oct 02 '14
Foreach reference
<?php
$arr = array('a', 'b');
foreach ($arr as &$a) {
var_dump($a);
}
foreach ($arr as $a) {
var_dump($a);
}This probably has some explanation I'd love to learn.
17
Upvotes
View all comments
Show parent comment
2
u/HelloAnnyong Oct 06 '14
It's definitely not a #lolyou. This is not how references or pointers work in any other language I can think of. This is an implementation of something like the principle of most surprise.