note 99909 added to control-structures.foreach
| From: | Olegenglishman at bigmir dot net | Date: | Tue, 14 Sep 2010 14:12:08 +0000 |
| Subject: | note 99909 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172543@lists.php.net to get a copy of this message | ||
For those who'd like to traverse an array including just added elements (within this very
foreach), here's a workaround:
<?
$values = array(1 => 'a', 2 => 'b', 3 => 'c');
while (list($key, $value) = each($values)) {
echo "$key => $value \r\n";
if ($key == 3) {
$values[4] = 'd';
}
if ($key == 4) {
$values[5] = 'e';
}
}
?>
the code above will output:
1 => a
2 => b
3 => c
4 => d
5 => e
----
Server IP: 88.81.245.102 (proxied: 91.196.196.205 1.0 localhost.ua.elro.com:3128
(squid/2.7.STABLE7))
Probable Submitter: 193.84.72.51
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- https://master.php.net/note/edit/99909
Del: integrated -- https://master.php.net/note/delete/99909/integrated
Del: useless -- https://master.php.net/note/delete/99909/useless
Del: bad code -- https://master.php.net/note/delete/99909/bad+code
Del: spam -- https://master.php.net/note/delete/99909/spam
Del: non-english -- https://master.php.net/note/delete/99909/non-english
Del: in docs -- https://master.php.net/note/delete/99909/in+docs
Del: other reasons-- https://master.php.net/note/delete/99909
Reject -- https://master.php.net/note/reject/99909
Search -- https://master.php.net/manage/user-notes.php