note 88583 deleted from control-structures.foreach by danbrown
| From: | danbrown@php.net | Date: | Fri, 30 Jan 2009 14:54:58 +0000 |
| Subject: | note 88583 deleted from control-structures.foreach by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149977@lists.php.net to get a copy of this message | ||
Note Submitter: scissor at phplabs dot pl
----
There is copy/paste mistake in previous example. The first loop should be foreach as below:
<?php
$arr = array(1,2,3,4,5,6,7,8,9);
foreach($arr as $key=>$value)
{
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