prev() definition and usage
The prev() function moves the pointer to the current element to the position of the previous element and returns the value of the element.
If the internal pointer has exceeded the first element of the array, the function returns false.
grammar
prev(array) parameter description
array Required. Specifies the array to be used.
illustrate
prev() behaves similarly to next(), but it rewinds the internal pointer one instead of moving it forward one.
Note: If the array contains empty cells, or the value of the cell is 0, the function will also return FALSE when encountering these cells. To correctly traverse an array that may contain empty cells or unit values 0, see the each() function.
example
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br />";
echo next($people) . "<br />";
echo prev($people);
?>
Output:
Peter
Joe
Peter
The prev() function moves the pointer to the current element to the position of the previous element and returns the value of the element.
If the internal pointer has exceeded the first element of the array, the function returns false.
grammar
prev(array) parameter description
array Required. Specifies the array to be used.
illustrate
prev() behaves similarly to next(), but it rewinds the internal pointer one instead of moving it forward one.
Note: If the array contains empty cells, or the value of the cell is 0, the function will also return FALSE when encountering these cells. To correctly traverse an array that may contain empty cells or unit values 0, see the each() function.
example
Copy the codeThe code is as follows:
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br />";
echo next($people) . "<br />";
echo prev($people);
?>
Output:
Peter
Joe
Peter