note 102924 added to control-structures.foreach

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

« previous php.notes (#177881) next »