|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2012-05-23 21:54 UTC] nikic@php.net
[2012-05-23 23:59 UTC] a dot protaskin at gmail dot com
[2012-05-24 01:47 UTC] laruence@php.net
-Status: Open
+Status: Not a bug
[2012-05-24 01:47 UTC] laruence@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 12:00:01 2025 UTC |
Description: ------------ Traversing the array changes once the internal pointer by 1. Traversing the array by link changes the internal pointer just as with each(). Test script: --------------- <?php $array = [0, 1, 2]; while (each($array)) { var_dump(key($array)); } reset($array); echo "----\n"; foreach ($array as $elem) { var_dump(key($array)); } reset($array); echo "----\n"; $array2 = &$array; foreach ($array2 as $elem) { var_dump(key($array)); } Expected result: ---------------- int(1) int(2) NULL ---- int(1) int(2) NULL ---- int(1) int(2) NULL Actual result: -------------- int(1) int(2) NULL ---- int(1) int(1) int(1) ---- int(1) int(2) NULL