Try using reset / while / each, which is functionally equivalent to foreach according to the manual, then you can use reset in a loop like this:
<?php
$arr = array(1=>'one',2=>'two',3=>'three');
reset($arr);
$resets=0;
while (list($key, $value) = each($arr))
{
echo "$key => $value<br />\n";
if($value=='three')
{
if($resets==0){$resets++;echo "==Resetting==<br />\n";reset($arr);continue;}
}
}
Output:
1 => one
2 => two
3 => three
== Resetting ==
1 => one
2 => two
3 => three
source
share