Home >Backend Development >PHP Tutorial >How to use prev function
PHP prev() function is used to rewind the internal pointer of the array one bit.
php prev() function Syntax
Function: Point the internal pointer to the previous element in the array and output it.
Syntax:
prev(array)
Parameters:
array Required. Specify the array to be operated on.
Note: If the array contains empty cells, or the value of the cell is 0, this function will also return FALSE when encountering these cells.
php prev() function example 1
<?php $people = array("西门", "灭绝", "无忌"); $people2 = next($people); //指向下一个元素 灭绝 echo $people2; echo "<br>"; $people3 = prev($people);//指向上一个元素 西门 echo $people3; ?>
Output:
灭绝 西门
php prev() function example 2
<?php $arr = array("peter", "官人", "欧阳克"); $arr2 = next($arr); //指向下一个元素 官人 echo $arr2; echo "<br>"; $arr3 = prev($arr);//指向上一个元素 peter echo $arr3; ?>
Output:
官人 peter
This article is an introduction to the PHP prev function. I hope it will be helpful to friends in need!
The above is the detailed content of How to use prev function. For more information, please follow other related articles on the PHP Chinese website!