php - Strange foreach loop after modifying array -


as wrote code, php confused me little didn't expected result of following code:

$data = array(array('test' => 'one'), array('test' => 'two'));  foreach($data &$entry) {     $entry['test'] .= '+'; }  foreach($data $entry) {     echo $entry['test']."\n"; } 

i think should output

one+ two+ 

however result is: http://ideone.com/e5tcsi

one+ one+ 

can explain me why?

this expected behaviour, see https://bugs.php.net/bug.php?id=29992.

the reference maintained when using second foreach, when using second foreach value of $entry, points still $data[1], overwritten first value.

p.s. (thanks @billyonecan saying it): need unset($entry) first, reference destroyed.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -