note 93149 deleted from control-structures.foreach by danbrown

From: Date: Tue, 30 Mar 2010 14:06:06 +0000
Subject: note 93149 deleted from control-structures.foreach by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-167526@lists.php.net to get a copy of this message
Note Submitter: hueen ---- In addition to the previous post by Krzysztof: The above manual states that "Reference of a $value and the last array element remain even after the foreach loop", but it should also be noted that foreach does not reinitialize $value _before_ iterating. This means that if $value is a reference (of anything) before a foreach($array as $value) loop, it will remain a reference while foreach is iterating (and thus the reference's target gets overwritten with each iteration). If that foreach is run by reference though (foreach($array as &$value)), $value's original reference inherently gets dropped and it references each current $array element instead (as expected).

« previous php.notes (#167526) next »