Home >Backend Development >PHP Tutorial >How to get the value of the first array element in php in php, php array_PHP tutorial
The example in this article describes the implementation method of obtaining the value of the first array element in the array element in PHP. Share it with everyone for your reference. The details are as follows:
In PHP’s built-in functions, the functions for obtaining the value of array elements mainly include reset next current prev end.
reset (PHP 3, PHP 4, PHP 5)
Function definition: mixed reset (array &array)
Function: This function rewinds the internal pointer of array to the first unit and returns the value of the first array unit. If the array is empty, it returns FALSE. The code is as follows:
Function definition: mixed next(array &array)
Function: Return the value of the next unit pointed to by the internal pointer of the array, or return FALSE when there are no more units. The code is as follows:
echo next($array);
//Output: step two
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 traverse the array that may contain empty cells or the value of the cell is 0, see the each() function.
current (PHP 3,PHP 4,PHP 5)
Function definition: mixed current (array &array)
Function: Returns the value of the array unit currently pointed to by the internal pointer, without moving the pointer. The initial point is the first unit inserted into the array. 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 tell with current() whether the end of this array list has been reached. To correctly iterate over an array that may contain empty cells, use the each() function.
next() behaves similarly to current(), except that 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.
The following are examples of using related functions, the code is as follows:
I hope this article will be helpful to everyone’s PHP programming design.