note 102909 deleted from control-structures.foreach by googleguy

From: Date: Wed, 14 Nov 2012 22:22:22 +0000
Subject: note 102909 deleted from control-structures.foreach by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-191947@lists.php.net to get a copy of this message
Note Submitter: benekastah at gmail dot com ---- 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.

« previous php.notes (#191947) next »