next() function in PHP


The next() function advance the internal array pointer of an array to the next element.

Syntax

next(arr)

Parameters

  • arr − The specified array

Return

The next() function returns the value of the next element in the array, on success. It returns FALSE, if no more elements are available.

Example

The following is an example −

 Live Demo

<?php
$os = array('windows', 'mac', 'linux', 'solaris');
echo current($os) . "<br>";
echo next($os);
?>

Output

windows
mac

Example

Let us see another example −

 Live Demo

<?php
$a = array('one', 'two', 'three', 'four', 'five', 'six' );
echo current($a)."
"; echo next($a)."
"; echo current($a)."
"; echo next($a)."
"; echo end($a)."
"; echo current($a)."
"; ?>

Output

one
two
two
three
six
six

Updated on: 23-Dec-2019

139 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements