note 69313 deleted from ref.array by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.