|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-10-08 18:13 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 15:00:01 2025 UTC |
Description: ------------ I know that the array pointer doing... if passing arrays to functions, the pointer of the argument(within the function) is set to First. and after the foreach, the pointer is set to First; But, some version of PHP (like 5.2.6 and 5.2.7-dev) array pointer is different from other version. Also, I ever seen it within one of early version of 5.2.6. test result... expected result: 5.0.4(FC 4) , 5.1.6(centos 5) actual result: 5.2.6(centos 4.6) , 5.2.7-dev(centos 4.6) Reproduce code: --------------- <? echo "PHP VER. ".phpversion()."<br><br>"; $a = array('aa'=>'aa','bb'=>'bb','cc'=>'cc'); $aa = array('a'=>$a,'b'=>$a,'c'=>$a); function testLoop($datas) { while (is_array($datas) && list($dk,$data) = each($datas)){ echo $dk ."<br>"; } } //next ($aa); foreach ($aa as $ak=>$av) unset ($aa[$ak]['bb']); list($k,$v) = each($aa); echo "$k , $v <br>"; echo "testLoop : unexpected result<br>"; testLoop($aa); echo "<br>rest & testLoop : expected result<br>"; reset($aa); testLoop($aa); ?> Expected result: ---------------- PHP VER. 5.0.4 a , Array testLoop : unexpected result a b c rest & testLoop : expected result a b c Actual result: -------------- PHP VER. 5.2.6 b , Array testLoop : unexpected result c rest & testLoop : expected result a b c