note 61359 deleted from control-structures.foreach by tularis

From: Date: Wed, 01 Feb 2006 16:33:15 +0000
Subject: note 61359 deleted from control-structures.foreach by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-102819@lists.php.net to get a copy of this message
Note Submitter: patrik dot mayer at i12 dot de Reason: bad code ---- While running through a foreach construct the array-count decreases... <?php $array = array('hi','hey','howdie'); $array_count = count($array); // this is 3 foreach($array AS $key => $value){ //if reeached the entry before the last one //doesn't work if($key == (count($array)-1) ){ echo "reached the second last one"; } //works if($key == ($array_count-1) ){ echo "reached the second last one"; } echo "Current #".count($array)."<br/>"; } ?>

« previous php.notes (#102819) next »