note 93149 added to control-structures.foreach

From: Date: Tue, 25 Aug 2009 18:15:58 +0000
Subject: note 93149 added to control-structures.foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-159886@lists.php.net to get a copy of this message
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). ---- Server IP: 69.147.83.197 Probable Submitter: 90.10.29.215 ---- Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php Edit -- https://master.php.net/note/edit/93149 Del: integrated -- https://master.php.net/note/delete/93149/integrated Del: useless -- https://master.php.net/note/delete/93149/useless Del: bad code -- https://master.php.net/note/delete/93149/bad+code Del: spam -- https://master.php.net/note/delete/93149/spam Del: non-english -- https://master.php.net/note/delete/93149/non-english Del: in docs -- https://master.php.net/note/delete/93149/in+docs Del: other reasons-- https://master.php.net/note/delete/93149 Reject -- https://master.php.net/note/reject/93149 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159886) next »