php foreach by reference

Here’s an interesting “feature” (bug?) for php. Recent PHP versions support this syntax for foreach: foreach ($myarray as &$v) $v[‘koko’]=’lala’; This allows easy changes to the actual table by using references and not acting on a copy. – but – If you do this: $myarray=array(array(‘a’=>1), array(‘a’=>2), array(‘a’=>3)); foreach ($myarray as &$v) $v[‘b’]=1; foreach ($myarray as …

Continue reading ‘php foreach by reference’ »