note 105765 modified in control-structures.foreach by danbrown
| From: | danbrown@php.net | Date: | Tue, 13 Sep 2011 14:27:29 +0000 |
| Subject: | note 105765 modified in control-structures.foreach by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-183148@lists.php.net to get a copy of this message | ||
<?php
foreach (array() as $value){
echo $value; // Prints nothing here
}
?>
The code above always prints nothing, because array() returns empty array. So $value always be empty
and echo has nothing to print - you never know if foreach is in loop.
--was--
<?php
foreach (array() as $value){
echo $value; // Prints nothing here
}
?>
The code above always prints nothing, because array() returns empty array. So $value always be empty
and echo has nothing to print - you never know if foreach is in loop.
If you would like to test how foreach works with empty array() try this code:
<?php
foreach (array() as $value) {
echo 'I wont read this';
}
?>
http://php.net/manual/en/control-structures.foreach.php