And that's exactly how I did it :)

Since 'for' is traditionally pre-testing with excetuting the condition prior 
looping it's working well :)

Thanks for all the help!

Cheers,

        Tamas

-----Original Message-----
From: Louis Huppenbauer [mailto:louis.huppenba...@gmail.com] 
Sent: Tuesday, July 05, 2011 5:47 PM
To: Robert Cummings
Cc: Dajka Tamás; php-general@lists.php.net
Subject: Re: [PHP] Foreach question

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);
                }
        }
?>

2011/7/5 Robert Cummings <rob...@interjinn.com>:
> On 11-07-05 10:48 AM, Dajka Tamás wrote:
>>
>> Thanks, that was interesting :) I think I got one step further in
>> understanding PHP :)
>>
>> BTW, I've changed the loop to 'for' and it's working well :)
>
> Can you show us your for loop? I'm not immediately sure how you use a for
> loop to traverse a growing number of entries in an array without either
> updating the extents of the traversal or using for( ; ; ) which is the same
> as while( 1 ). Or are you now using the low level array traversal functions
> like reset() and next()?
>
> 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.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to