PHP next() function to move the internal array pointer

Updated


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
Comment
Mithlesh Upadhyay Published 29 Nov 2026 · 2 min read

Mithlesh Upadhyay is a Computer Science and AI expert from Madhya Pradesh with strong academic background (BE in CSE and M.Tech in AI) and over six years of experience in technical content development. He has contributed tech articles, led teams, and worked in Full Stack Development and Data Science. He founded the w3colleges.org portal for learning resources.

Related tutorials

  • Classes and objects in TypeScript with examples

    Class in term of OOps is, it is blueprint for creating objects. TypeScript supports object-oriented programming features like classes, Interfaces, Polymorphism, data-binding etc. Object means this an real…

    3 min read
  • Check whether a number is even or odd in PHP

    Numbers can be Even or Odd, we call as Even when it is divided by 2 and remainder is 0, we call as Odd when it is divided…

    3 min read
  • Web workers in JavaScript for multi-threading

    In many situations, having more than one thread running in a program is beneficial. We really have to start thinking about how our program can do multiple things…

    4 min read
  • Sort an array of objects by a field in PHP

    Write a program in Php to sort an array of objects by any object field. Here, we will take a array of student with fields as Id, Name,…

    2 min read
  • What are the advantages of the Internet?

    Here in this article we will discuss about the various ways through which the net is headed up in the world. Employment Opportunities: Employment opportunities will get open…

    4 min read