note 102924 deleted from control-structures.foreach by danbrown

From: Date: Tue, 15 Mar 2011 13:43:05 +0000
Subject: note 102924 deleted from control-structures.foreach by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177889@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- @benekastah The behavior you've noticed actually makes perfect sense and should not be an error. However, you are probably wrong about one minor point. $somearray = array('a','b','c','d'); // this (probably) iterates the whole array, doing nothing on each iteration. foreach($somearray as $item); //now $item has the value of the last item in the array as it would after any other use of foreach echo $item; // echos 'd' // see? foreach($somearray as $item) { echo $item; } // echos 'abcd' echo $item; // echos 'd'

« previous php.notes (#177889) next »