note 102909 added to control-structures.foreach

From: Date: Mon, 14 Mar 2011 17:26:04 +0000
Subject: note 102909 added to control-structures.foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-177860@lists.php.net to get a copy of this message
It's good to know that if you accidentally (or purposefully) put a semicolon at the end of the first line of a foreach statement, no error or warning will be thrown. Instead, the foreach will iterate only on the last entry in the array. Therefore, <?php $array = array('a', 'b', 'c', 'd'); foreach ( $array as $letter ); // <--Semicolon at end of foreach statement echo $letter; ?> will only echo 'd' as it's response (rather than 'abcd'). I don't know if this is meant to be the case, or if it is meant to err. ---- Server IP: 69.147.83.197 Probable Submitter: 128.187.97.4 ---- Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php Edit -- https://master.php.net/note/edit/102909 Del: integrated -- https://master.php.net/note/delete/102909/integrated Del: useless -- https://master.php.net/note/delete/102909/useless Del: bad code -- https://master.php.net/note/delete/102909/bad+code Del: spam -- https://master.php.net/note/delete/102909/spam Del: non-english -- https://master.php.net/note/delete/102909/non-english Del: in docs -- https://master.php.net/note/delete/102909/in+docs Del: other reasons-- https://master.php.net/note/delete/102909 Reject -- https://master.php.net/note/reject/102909 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#177860) next »