English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The next() function returns the value of the next array element and moves the array pointer forward by one position.
next(array $array);
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.
Number | Parameters and Description |
---|---|
1 | array(Required) It specifies an array |
It returns the next element in the array.
<?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'; ?>