|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-01-10 12:22 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 03:00:01 2025 UTC |
Description: ------------ If I declare a reference variable (&$value) and use it in a 'foreach' and then I reuse it in the same loop like a normal variable ($value), I have an unexpected result, array is modified! Note that using another variable in the second 'foreach' the result is Ok. Reproduce code: --------------- <?php $v = array (1,2,3); foreach($v as &$value); print_r($v); foreach($v as $value); print_r($v); ?> Expected result: ---------------- Array ( [0] => 1 [1] => 2 [2] => 3 ) Array ( [0] => 1 [1] => 2 [2] => 3 ) Actual result: -------------- Array ( [0] => 1 [1] => 2 [2] => 3 ) Array ( [0] => 1 [1] => 2 [2] => 2 )