given the following code
<?php
$a = array(1,2,3,4,5,6);
$c=0;
foreach($a as $v){
if($v==5&&$c==0){
$c=1;
reset($a);
}
var_dump($v);
}
How do I reset the pointer so it will print 1,2,3,4,5,1,2,3,4,5,6 ?
I know that in this case I can simply
<?php
$a = array(1,2,3,4,5,6);
$c=0;
for($i=0;$i<count($a);++$i){
$v = $a[$i];
if($v==5&&$c==0){
$c=1;
$i=-1; //because of the loop ++$i
}
var_dump($v);
}
But I have a much more complex piece of code and the solution is not as simple as rewrite the loop (not numeric keys).
Any PHP guru out there that can help me here ?