PHP » Arrays » next()

Syntax:
mixed next(array array)
array
The array to get the next element from.

Returns the next element.

The next() function moves the internal pointer of an array to the next element and returns that element.

Examples

Code:
<?php

$array1 = array(21, 53, 5, 8, 32, 77);

while ($element = current($array1)) {
   if ($element % 2 == 0)
      break;
   next($array1);
}

print "The first element divisible by 2: $element";


?>
Output:
The first element divisible by 2: 8
Explanation:

The code looks for the first element divisible by two in an array.

See Also: