Re: [PHP] Rewind foreach loop
- From: dmagick@xxxxxxxxx (Chris)
- Date: Fri, 30 Nov 2007 14:13:52 +1100
Jeffery Fernandez wrote:
On Fri, 30 Nov 2007 02:01:47 pm Chris wrote:Jeffery Fernandez wrote:Hi all,echo $numbers[$index-1] . PHP_EOL;
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?
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.
and you're going to be in an endless loop then.. because each time it gets rewound, it gets the same key again and rewinds and ...
You could do it with a for or while loop probably.
What are you trying to achieve? Maybe there's an alternative.
--
Postgresql & php tutorials
http://www.designmagick.com/
.
- Follow-Ups:
- Re: [PHP] Rewind foreach loop
- From: Jeffery Fernandez
- Re: [PHP] Rewind foreach loop
- From: Casey
- Re: [PHP] Rewind foreach loop
- References:
- Rewind foreach loop
- From: Jeffery Fernandez
- Re: [PHP] Rewind foreach loop
- From: Chris
- Re: [PHP] Rewind foreach loop
- From: Jeffery Fernandez
- Rewind foreach loop
- Prev by Date: Re: Rewind foreach loop
- Next by Date: Re: [PHP] Rewind foreach loop
- Previous by thread: Re: [PHP] Rewind foreach loop
- Next by thread: Re: [PHP] Rewind foreach loop
- Index(es):
Relevant Pages
|