note 114487 added to control-structures.foreach
| From: | wowsrs at mail dot ru | Date: | Wed, 26 Feb 2014 10:31:59 +0000 |
| Subject: | note 114487 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198729@lists.php.net to get a copy of this message | ||
<?php
echo 'test 1:<br>';
$items = array(
'qwerty',
'qwerty2',
'qwerty3',
'qwerty4',
'qwerty5',
'qwerty6',
'qwerty7',
);
foreach ($items as $item) {
echo $item.'<br>';
if ($item == 'qwerty4') {
echo '---add item to array<br>';
$items[] = 'qwerty8';
}
}
echo '<br>';
echo 'test 2:<br>';
$items = array(
'qwerty',
'qwerty2',
'qwerty3',
'qwerty4',
'qwerty5',
'qwerty6',
'qwerty7',
);
reset($items);
while (list($k, $item) = each($items)) {
echo $item.'<br>';
if ($item == 'qwerty4') {
echo '---add item to array<br>';
$items[] = 'qwerty8';
}
}
?>
---------
result:
---------
test 1:
qwerty
qwerty2
qwerty3
qwerty4
qwerty5
qwerty6
qwerty7
test 2:
qwerty
qwerty2
qwerty3
qwerty4
---add item to array
qwerty5
qwerty6
qwerty7
qwerty8
----
Server IP: 195.54.192.44
Probable Submitter: 94.158.105.158
----
Manual Page -- http://php.net/manual/en/control-structures.foreach.php
Edit -- https://master.php.net/note/edit/114487
Del: integrated -- https://master.php.net/note/delete/114487/integrated
Del: useless -- https://master.php.net/note/delete/114487/useless
Del: bad code -- https://master.php.net/note/delete/114487/bad+code
Del: spam -- https://master.php.net/note/delete/114487/spam
Del: non-english -- https://master.php.net/note/delete/114487/non-english
Del: in docs -- https://master.php.net/note/delete/114487/in+docs
Del: other reasons-- https://master.php.net/note/delete/114487
Reject -- https://master.php.net/note/reject/114487
Search -- https://master.php.net/manage/user-notes.php