|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-01-18 11:41 UTC] potyo dot ada at gmail dot com
[2013-01-18 12:15 UTC] cataphract@php.net
-Status: Open
+Status: Not a bug
[2013-01-18 12:15 UTC] cataphract@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 11 01:00:02 2025 UTC |
Description: ------------ If we try to change the array elements in one foreach loop using referenced $value, and in a second foreach loop remove some elements from the array, then the resulting array misses some element, some elements are duplicated, or simply nothing is removed, depending on that, which element we want to remove from the array in the second loop. Test script: --------------- $a=array(array('a'=>'11', 'aa'=>'22'), array('a'=>'33', 'aa'=>'44'), array('a'=>'55', 'aa'=>'66')); foreach ($a as &$v) // if we use $k=>$v here { $v['c']='99'; // and $a[$k]['c']='99' here, then it produces the expected result } foreach ($a as $k=>$v) { if ($v['aa']=='22') { unset($a[$k]); // } } print_r($a); Expected result: ---------------- Array ( [1] => Array ( [a] => 33 [aa] => 44 [c] => 99 ) [2] => Array ( [a] => 33 [aa] => 44 [c] => 99 ) ) Actual result: -------------- Array ( [1] => Array ( [a] => 33 [aa] => 44 [c] => 99 ) [2] => Array ( [a] => 55 [aa] => 66 [c] => 99 ) )