Re: [PHP] Rewind foreach loop

2007-11-30 Thread Robert Cummings
On Fri, 2007-11-30 at 14:46 -0500, Robert Cummings wrote: This is dangerous use of the array functions. A problem occurs when you have a value that evaluates to false (such as the first entry in the example array :). In fact the only way to ensure you traverse the array properly is to use

Re: [PHP] Rewind foreach loop

2007-11-30 Thread Robert Cummings
On Fri, 2007-11-30 at 09:51 -0800, Jim Lucas 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) {

Re: [PHP] Rewind foreach loop

2007-11-30 Thread Jim Lucas
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

Re: [PHP] Rewind foreach loop

2007-11-30 Thread Jochem Maas
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; }

Re: [PHP] Rewind foreach loop

2007-11-29 Thread Jeffery Fernandez
I think the best option for me is to refactorise my code a bit to cater to my situation. Thanks all for your help. Jeffery On Fri, 30 Nov 2007 02:32:11 pm Jeffery Fernandez wrote: On Fri, 30 Nov 2007 02:13:52 pm Chris wrote: Jeffery Fernandez wrote: On Fri, 30 Nov 2007 02:01:47 pm Chris

Re: [PHP] Rewind foreach loop

2007-11-29 Thread Casey
$keys = array_values($array); for ($i=0; $icount($keys); $i++) { if ($keys[$i] == 5) $i -= 2; } Untested, but should work. On Nov 29, 2007, at 7:13 PM, Chris [EMAIL PROTECTED] wrote: Jeffery Fernandez wrote: On Fri, 30 Nov 2007 02:01:47 pm Chris wrote: Jeffery Fernandez wrote:

Re: [PHP] Rewind foreach loop

2007-11-29 Thread Steve Edberg
At 2:11 PM +1100 11/30/07, Jeffery Fernandez wrote: On Fri, 30 Nov 2007 02:01:47 pm Chris [EMAIL PROTECTED] 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) {

Re: [PHP] Rewind foreach loop

2007-11-29 Thread Chris
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

Re: [PHP] Rewind foreach loop

2007-11-29 Thread Jeffery Fernandez
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);

Re: [PHP] Rewind foreach loop

2007-11-29 Thread Chris
Jeffery Fernandez wrote: 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) {

Re: [PHP] Rewind foreach loop

2007-11-29 Thread Jeffery Fernandez
On Fri, 30 Nov 2007 02:13:52 pm Chris wrote: Jeffery Fernandez wrote: 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) {