note 114487 deleted from control-structures.foreach by mazzanet
| From: | mazzanet@php.net | Date: | Thu, 27 Feb 2014 10:29:54 +0000 |
| Subject: | note 114487 deleted from control-structures.foreach by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-198737@lists.php.net to get a copy of this message | ||
Note Submitter: wowsrs at mail dot ru
----
<?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