Go back to the beginning of the foreach loop in PHP
5 answers
You can use the current (), next (), and prev () functions to cycle through the array and move the internal array pointer back and forth:
$items = array("apple", "box", "cat");
while($item=current($items)) {
print_r($item);
if (needToGoBack($item))
// Go to previous array item
$item = reset($items);
} else {
// Continue to next
$item = next($items);
}
}
+1
source to share