Home > Backend Development > PHP Tutorial > How to use prev function

How to use prev function

藏色散人
Release: 2023-04-05 07:14:01
Original
4072 people have browsed it

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)
Copy after login

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;
?>
Copy after login

Output:

灭绝
西门
Copy after login

php prev() function example 2

<?php
$arr = array("peter", "官人", "欧阳克");
$arr2 = next($arr); //指向下一个元素 官人
echo $arr2;
echo "<br>";
$arr3 = prev($arr);//指向上一个元素 peter
echo $arr3;
?>
Copy after login

Output:

官人
peter
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template