prev
(PHP 4, PHP 5, PHP 7, PHP 8)
Rewind the internal array pointer
Description
Rewind the internal array pointer.
prev() behaves just like next(), except it rewinds the internal array pointer one place instead of advancing it.
Parameters
arrayThe input array.
Return Values
Returns the array value in the previous place that's pointed to by the internal array pointer, or false if there are no more elements.
Falseproblem
Changelog
| Version | Description |
|---|
Examples
Example use of prev() and friends
<?php
$transport = array('foot', 'bike', 'car', 'plane');
echo $mode = current($transport), PHP_EOL; // $mode = 'foot';
echo $mode = next($transport), PHP_EOL; // $mode = 'bike';
echo $mode = next($transport), PHP_EOL; // $mode = 'car';
echo $mode = prev($transport), PHP_EOL; // $mode = 'bike';
echo $mode = end($transport), PHP_EOL; // $mode = 'plane';
?>Notes
The beginning of an array is indistinguishable from a bool false element. To make the distinction, check that the key() of the prev() element is not null.