note 69313 deleted from ref.array by felipe

From: Date: Sun, 30 Dec 2007 19:26:12 +0000
Subject: note 69313 deleted from ref.array by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-134512@lists.php.net to get a copy of this message
Note Submitter: jeremyquinton at gmail dot com ---- //using the foreach loop of php instead of a normal //for loop with the sizeof operator after unset is used. $values = array(); array_push($values,"lion"); array_push($values,"elephant"); array_push($values,"cheetah"); array_push($values,"wildebeest"); unset($values[2]); //normal for loop thinks array size is three //when sizoef function is used in conjunction //the for loop. for($i = 0;$i < sizeof($values); $i++) { echo "animals " . $values[$i]. "\n"; } //prints animals lion animals elephant animals echo "\n"; //foreach prints the three values left properly foreach($values as $animals) { echo "animal " . $animals. "\n"; } //prints animal lion animal elephant animal wildebeest //simple but valid

« previous php.notes (#134512) next »