note 81459 modified in control-structures.foreach by danbrown
| From: | danbrown@php.net | Date: | Tue, 28 Apr 2009 13:03:12 +0000 |
| Subject: | note 81459 modified in control-structures.foreach by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153903@lists.php.net to get a copy of this message | ||
Also, do not forget that foreach is not useful
if you change the value inside of the loop.
For example:
<?php
$t=array('a', 'a', 'a', 'a', 'a', 'a',
'a', '1', 'a', 'a', 'a', 'a',
'a');
foreach($t as $var=>$val)
{
$t=array();
echo "val={$val}<br>";
}
?>
is still showing the contents of the array $t.
--was--
Also, do not forget that foreach is not useful
if you change the value inside of the loop.
For example:
$t=array('a', 'a', 'a', 'a', 'a', 'a',
'a', '1', 'a', 'a', 'a', 'a',
'a');
foreach($t as $var=>$val)
{
$t=array();
echo "val={$val}<br>";
}
is still showing the contents of the array $t.
http://php.net/manual/en/control-structures.foreach.php