Re: Foreach question
| From: | Robert Cummings | Date: | Tue, 05 Jul 2011 16:12:46 +0000 |
| Subject: | Re: Foreach question | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-313908@lists.php.net to get a copy of this message | ||
On 11-07-05 11:46 AM, Louis Huppenbauer wrote:
Just use count($arr) in your for-header, as it get's executed again
for each loop.
<?php
$arr = array(array('id'=>1), array('id'=>2));
for($i=0;$i<count($arr);$i++) {
echo $arr[$i]['id'];
if($i< 6) {
$arr[] = array('id' => $arr[$i]['id']+1);
}
}
?>
Ok, so the extents are being updated on each pass of the loop :)
Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.