Definition
The next() function moves the internal pointer of an array to the next element, and returns its value.
The next() function is commonly used along with the following functions:
- current() – Returns the value of the current element in an array.
- end() – Moves the internal pointer of an array to its last element, and returns its value.
- prev() – Moves the internal pointer of an array to the previous element, and returns its value.
- reset() – Set the internal pointer of an array to its first element, and returns its value.
- key() – Returns the key of the current element in an array.
Syntax
next(array)
Parameters
Parameter | Description |
---|---|
array |
Required. Specifies the array to work on. |
Example
<?php
// Example 1
$cities = array("New York", "London", "Tokyo");
echo current($cities) . "<br>";
echo next($cities) . "<br>";
// Examples in conjunction with other related functions
$ages = array("Mark" => 22, "Jeff" => 32, "Mike" => 28);
echo current($ages) . "<br>";
echo next($ages) . "<br>";
echo current($ages) . "<br>";
echo prev($ages) . "<br>";
echo end($ages) . "<br>";
echo prev($ages) . "<br>";
echo current($ages) . "<br>";
echo reset($ages) . "<br>";
echo next($ages) . "<br>";