Home  >  Article  >  Backend Development  >  PHP array function sequence prev() - moves the internal pointer of the array to the position of the previous element and returns the element value_PHP tutorial

PHP array function sequence prev() - moves the internal pointer of the array to the position of the previous element and returns the element value_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:23:27953browse

prev() Definition and Usage
prev() function moves the pointer pointing to the current element to the position of the previous element and returns the element value.

If the internal pointer has passed before the first element of the array, the function returns false.

Syntax
prev(array) Parameter Description
array Required. Specifies the array to use.

Explanation
prev() behaves similarly to next(), except that it rewinds the internal pointer one position instead of moving it forward.

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. To correctly iterate over an array that may contain empty cells or a cell value of 0, see the each() function.

Example

Copy code The code is as follows:

$people = array ("Peter", "Joe", "Glenn", "Cleveland");

echo current($people) . "
";
echo next($people) . "
";
echo prev($people);
?>

Output:

Peter
Joe
Peter

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324474.htmlTechArticleprev() Definition and Usage The prev() function moves the pointer to the current element to the position of the previous element. and returns the element value. If the internal pointer has exceeded the first element of the array...
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