PHP next() function

PHP pos() function
PHP prev() function

In the article, you will learn how to move the internal pointer of an array to the next element, The next() function moves the internal pointer to the next element (if present) and outputs it.

What is the syntax of the next() function in PHP?

next(array)
ParameterDetails
arrayThe array to get the next element of – Required
PHP next() function

Examples of next() function

Example 1. Get the current and the next value of the array.

<?php
$arr= array("Jawad", "Ahmad", "Sumerina");
echo current($arr);
echo next($arr);
?>

Example 2. In this example, you will find all the methods related to the next method category. These methods work with the internal pointer of the arrays.

<?php
$members= array("Jawad", "Ahmad", "Sumerina", "ACS");

// Current element: Jawad
echo current($people) . "<br>";

// Next element of Jawad: Ahmad
echo next($people) . "<br>"; 

// Now the current element: Ahmad
echo current($people) . "<br>"; 

// Previous element of Ahmad: Jawad
echo prev($people) . "<br>"; 

// Last element: ACS
echo end($people) . "<br>"; 

// Previous element of ACS: Sumerina
echo prev($people) . "<br>"; 

// Current element: Sumerina
echo current($people) . "<br>"; 

// Move the internal pointer to the first element of the array:Jawad
echo reset($people) . "<br>"; 

// Next element of Jawad: Ahmad
echo next($people) . "<br>"; 

// Get key and value of Ahmad (current element) then moves the internal pointer forward
print_r (each($members));
?>
PHP pos() function
PHP prev() function

Stay up-to-date about PHP!

We don’t spam!

en English
X
Scroll to Top