English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP next() Function Usage and Example

PHP Array Function Manual

The next() function returns the value of the next array element and moves the array pointer forward by one position.

Syntax

next(array $array);

Definition and Usage

The behavior of next() and current() is similar, but there is one difference. It moves the internal pointer forward before returning the value. This means it returns the value of the next array element and moves the array pointer forward by one position. If there are no more elements, it returns FALSE.

Parameter

NumberParameters and Description
1

array(Required)

It specifies an array

Return value

It returns the next element in the array.

Online example

<?php
   $input = array('foot', 'bike', 'car', 'plane');
   $mode = current($input); 
   print "$mode <br />";
   
   $mode = next($input);
   print "$mode <br />";
   
?>
Test and see‹/›

Output result:

foot
bike

 Usage examples of next() and related functions

<?php
$transport = array('foot', 'bike', 'car', 'plane');
$mode = current($transport); // $mode = 'foot';
$mode = next($transport);    // $mode = 'bike';
$mode = next($transport);    // $mode = 'car';
$mode = prev($transport);    // $mode = 'bike';
$mode = end($transport);     // $mode = 'plane';
?>

   PHP Array Function Manual