|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-11-12 10:36 UTC] tony2001@php.net
[2007-11-12 11:10 UTC] denis at edistar dot com
[2007-11-13 11:46 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Mon Jan 05 03:00:01 2026 UTC |
Description: ------------ In PHP 5.2.4 when I set array values inside a foreach, the array pointer is moved to the second element of the array or, better, to the element after the first modified element of the array. In PHP 5.2.3 the array pointer was not moved. Moreover this does not happen if i assign the array elements outside the foreach. Reproduce code: --------------- $parameters = array( 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4 ); echo "\$parameters key before foreach: " . key($parameters) . "\n"; foreach($parameters as $key => $value) { $parameters[$key] = "s" . $value; } echo "\$parameters key after foreach: " . key($parameters) . "\n"; echo "\$parameters key before foreach: " . key($parameters) . "\n"; $parameters['a'] = "s" . 1; $parameters['b'] = "s" . 2; $parameters['c'] = "s" . 3; $parameters['d'] = "s" . 4; echo "\$parameters key after foreach: " . key($parameters) . "\n"; Expected result: ---------------- $parameters key before foreach: a $parameters key before foreach: a $parameters key before foreach: a $parameters key before foreach: a Actual result: -------------- $parameters key before foreach: a $parameters key before foreach: b $parameters key before foreach: a $parameters key before foreach: a