next
Advances the array's internal pointer to the next element.
Syntax
next(array|object &$array): mixedParameters
| Parameter | Type | Description |
|---|---|---|
| $array | array|object | The array. |
Return value
mixedThe next element, or `false` if there are no more elements.
Examples
The second element of an array:
<?php
$colors = ['red', 'green', 'blue'];
echo next($colors), ' ', next($colors), "\n";
var_dump(next($colors));Output:
green blue
bool(false)Notes
false is returned both at the end of the array and when the element itself is false. prev() moves backwards.
See also
In the tutorial
- Arrays — Lists and associative arrays in PHP — creating, changing, iterating and useful functions.