|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-02-27 05:00 UTC] same at saeven dot net
[2007-02-27 12:30 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 18:00:01 2025 UTC |
Description: ------------ Using a reference to build an array, later causes foreach to fail when reusing the reference variable name. The bug is solved by adding unset( $element); before block B, but this shouldn't be necessary. Reproduce code: --------------- // Block A - Build the Array $a = array( 2 => array( "value" => "a" ), 4 => array( "value" => "b" ), 6 => array( "value" => "c" ) ); $b = array( "orange", "blue", "green" ); foreach( $a as $id => &$element ){ $extra = array(); foreach( $b as $color ) array_push( $extra, $color ); $element += array( 'extra' => $extra ); } // Block B - Iterate through foreach( $a as $element ) echo $element["value"].' '; Expected result: ---------------- a b c Actual result: -------------- a b b