PHP next() Function (original) (raw)

Last Updated : 20 Jun, 2023

The next() function is an inbuilt function in PHP and does the following operations:

Syntax:

next($array)

Parameter: It accepts only one parameter $array. This parameter is mandatory. It is the array in which we need to find the next element.

Return Value: The function returns the value of the next element in an array of which the internal pointer is currently pointing to. It returns FALSE if there is no element at next. Initially the next() function returns the second inserted element.

Examples:

Input : array = [1, 2, 3, 4] Output : 2

Input : array = [1, 2, 3, 4], next() function executed two times
Output : 2 3

Below programs illustrate the next() function in PHP:

Program 1:

<?php

$array = array ( "geeks" , "Raj" , "striver" ,

`` "coding" , "RAj" );

echo next( $array );

?>

Output:

Raj

Program 2:

<?php

$array = array ( "geeks" , "Raj" , "striver" , "coding" , "RAj" );

echo current( $array ), "\n" ;

echo next( $array ), "\n" ;

echo current( $array ), "\n" ;

echo next( $array ), "\n" ;

echo current( $array ), "\n" ;

echo next( $array ), "\n" ;

echo current( $array ), "\n" ;

?>

Output:

geeks Raj Raj striver striver coding coding

Reference:
http://php.net/manual/en/function.next.php