Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

next

Advances the array's internal pointer to the next element.

Syntax

next(array|object &$array): mixed

Parameters

ParameterTypeDescription
$arrayarray|objectThe array.

Return value

mixedThe next element, or `false` if there are no more elements.

Examples

The second element of an array:

<?php
 
$colors = ['red', 'green', 'blue'];
 
echo next($colors), ' ', next($colors), "\n";
var_dump(next($colors));

Output:

green blue
bool(false)

Notes

false is returned both at the end of the array and when the element itself is false. prev() moves backwards.

See also

  • current — Returns the element the array's internal pointer points to.
  • reset — Returns the first element of an array.
  • end — Returns the last element of an array.

In the tutorial

  • Arrays — Lists and associative arrays in PHP — creating, changing, iterating and useful functions.

Thanks for reading!

Donate to the site — we work hard for you.