note 88578 added to control-structures.foreach
| From: | tedivm at tedivm dot com | Date: | Thu, 29 Jan 2009 22:44:47 +0000 |
| Subject: | note 88578 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-149959@lists.php.net to get a copy of this message | ||
foreach and the while/list/each methods are not completely identical, and there are occasions where
one way is beneficial over the other.
<?php
$arr = array(1,2,3,4,5,6,7,8,9);
while (list($key, $value) = each($arr))
{
unset($arr[$key + 1]);
echo $value . PHP_EOL;
}
?>
Output:
1 2 3 4 5 6 7 8 9
<?php
$arr = array(1,2,3,4,5,6,7,8,9);
while (list($key, $value) = each($arr))
{
unset($arr[$key + 1]);
echo $value . PHP_EOL;
}
?>
Output:
1 3 5 7 9
----
Server IP: 64.71.164.2
Probable Submitter: 71.89.1.242
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- https://master.php.net/note/edit/88578
Del: integrated -- https://master.php.net/note/delete/88578/integrated
Del: useless -- https://master.php.net/note/delete/88578/useless
Del: bad code -- https://master.php.net/note/delete/88578/bad+code
Del: spam -- https://master.php.net/note/delete/88578/spam
Del: non-english -- https://master.php.net/note/delete/88578/non-english
Del: in docs -- https://master.php.net/note/delete/88578/in+docs
Del: other reasons-- https://master.php.net/note/delete/88578
Reject -- https://master.php.net/note/reject/88578
Search -- https://master.php.net/manage/user-notes.php