I need to know if an array has more items, but without moving array's internail pointer. Thats is, a has_next() function:
<?php
function has_next($array) {
if (is_array($array)) {
if (next($array) === false) {
return false;
} else {
return true;
}
} else {
return false;
}
}
$array = array('fruit', 'melon');
if (has_next($array)) {
echo next($array);
}
// prints 'melon'
?>
Since you do not pass the array by reference, its pointer is only moved inside the function.
Hope that helps.