Re: Rewind foreach loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 30 Nov 2007 02:01:47 pm Chris wrote:
> Jeffery Fernandez wrote:
> > Hi all,
> >
> > Is it possible to rewind a foreach loop? eg:
> >
> >
> > $numbers = array(0,1,2,3,4,5,6,7,8,9,10);
> >
> > foreach ($numbers as $index => $value)
> > {
> >         if ($value == 5)
> >         {
> >                 prev($numbers);
> >         }
> >         echo "Value: $value" . PHP_EOL;
> > }
> >
> > The above doesn't seem to work. In one of my scenarios, when I encounter
> > and error in a foreach loop, I need the ability to rewind the array
> > pointer by one. How can I achieve this?
>
> echo $numbers[$index-1] . PHP_EOL;

That will only give me the value of the previous index. What I want is to 
rewind the array pointer and continue with the loop.

>
> Of course that assumes that the value you're looking for isn't the first
> element :)
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/



-- 
Internet Vision Technologies
Level 1, 520 Dorset Road
Croydon
Victoria - 3136
Australia
web: http://www.ivt.com.au
phone: +61 3 9723 9399
fax: +61 3 9723 4899

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux