note 25263 modified in control-structures.foreach by danbrown
| From: | danbrown@php.net | Date: | Tue, 28 Apr 2009 13:13:04 +0000 |
| Subject: | note 25263 modified in control-structures.foreach by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153931@lists.php.net to get a copy of this message | ||
"Also note that foreach operates on a copy of the specified array, not the array itself,
therefore the array pointer is not modified as with the each() construct and changes to the array
element returned are not reflected in the original array."
In other words, this will work (not too expected):
<?php
foreach ($array as $array) {
// ...
}
?>
While this won't:
<?php
while (list(, $array) = each($array)) {
// ...
}
?>
--was--
"Also note that foreach operates on a copy of the specified array, not the array itself,
therefore the array pointer is not modified as with the each() construct and changes to the array
element returned are not reflected in the original array."
In other words, this will work (not too expected):
foreach ($array as $array) {
// ...
}
While this won't:
while (list(, $array) = each($array)) {
// ...
}
http://php.net/manual/en/control-structures.foreach.php