PHP 8.5.0 Beta 2 available for testing

Voting

: min(one, five)?
(Example: nine)

The Note You're Voting On

papipo's gmail account
20 years ago
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.

<< Back to user notes page

To Top