|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-10-10 13:43 UTC] tony2001@php.net
[2006-10-10 13:57 UTC] perso at cyprien dot org
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 05:00:02 2025 UTC |
Description: ------------ Foreach loop access original array when using references on a previous loop. Reproduce code: --------------- <?php $list = array( 1, 2, 3, 4 ); $new_list = array(); foreach( $list as $item ){ $z =& $new_list[]; $z = $item; } //unset( $z ); print_r( $new_list ); foreach( $new_list as $z ){ } print_r( $new_list ); ?> Expected result: ---------------- Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) Actual result: -------------- Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 3 )