Home  >  Article  >  Backend Development  >  How to use prev function

How to use prev function

藏色散人
藏色散人Original
2019-02-12 10:12:444061browse

PHP prev() function is used to rewind the internal pointer of the array one bit.

How to use prev function

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to use next functionNext article:How to use next function