Home > Article > Backend Development > How to get the first value of an array in php_PHP Tutorial
reset (PHP 3, PHP 4, PHP 5)
reset -- Point the internal pointer of the array to the first element
Explanation
mixed reset (array &array)
reset() rewinds array's internal pointer to the first element and returns the first array element The value, returns FALSE if the array is empty.
Example 1. reset() example
Description
mixed next ( array &array )
Returns the value of the next cell pointed to by the array's internal pointer, or FALSE when there are no more cells.
next() behaves similarly to current(), with one difference: the internal pointer is moved forward one position before returning the value. This means that it returns the value of the next array element and moves the array pointer forward one position. If moving the pointer results in moving the pointer beyond the end of the array element, next() returns FALSE.
Warning
If the array contains empty cells, or the value of the cell is 0, this function will also return FALSE when encountering these cells. To correctly iterate over an array that may contain empty cells or a cell value of 0, see the each() function.
Example 1. Usage examples of next() and related functions
Description
mixed current ( array &array )
Each array has an internal pointer pointing to its "current" cell, initially pointing to the first cell inserted into the array.
The current() function returns the value of the array unit currently pointed to by the internal pointer, without moving the pointer. If the internal pointer points beyond the end of the unit list, current() returns FALSE.
Warning
If the array contains an empty cell (0 or "", empty string), this function will also return FALSE when encountering this cell. This makes it impossible to use current() to determine whether the end of the array list has been reached. To correctly iterate over an array that may contain empty cells, use the each() function.
Example 1. Usage examples of current() and related functions