The next() function is another inbuilt function in php. this next() function is used to moves the internal pointer to the next element in the array.this function behaves same as current() function with one difference that is it returns the next array value and increments the internal pointer of the array.
Syntax :
next($array)
Parameter: The next() function accepts a single parameter as shown above in syntax and described below.
$array :
- It is the array of which we want to find the next element.
Return Value :
It returns the value of the element in the array which the internal pointer is next palce pointing to. If the array is empty then the next() function returns FALSE.
Examples :
Input : next(array("raj", "ravi", "anshu", "d"))
Output : ravi
Explanation :
As we can see here that input array contains many elements and the
ouput is "ravi" because first element is raj and current element here
and ravi is the next element here.
Input : next(array("mnb", "uv", "sid", "lara"))
Output : uv
Below programs illustrate the next() function in PHP:
PROGRAM 1 :
<?php
// input array
$people = array("raj", "emi", "anny", "amo");
echo current($people) . "\n";
echo next($people);
?>
Output :
raj emi
PROGRAM 2 :
<?php
$people = array("abc", "xyz", "kmn", "mao");
echo current($people) . "\n";
echo next($people). "\n";
echo next($people);
?>
Output :
abc xyz kmn