PHP prev () function
Examples
The output of the current element in the array, the next element and an element of value:
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>";
echo next($people) . "<br>";
echo prev($people);
?>
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>";
echo next($people) . "<br>";
echo prev($people);
?>
Running instance »
Definition and Usage
prev () function internal pointer to the last element of the array, and output.
Related methods:
- Next () - the internal pointer to the next element in the array, and outputs.
- Current () - Returns the value of the current element in the array.
- End () - the internal pointer to the last element in the array, and output.
- RESET () - the internal pointer to the first element in the array, and output.
- the each () - Returns the current element's key names and values, and the internal pointer moves forward.
grammar
prev( array )
参数 | 描述 |
---|---|
array | 必需。规定要使用的数组。 |
technical details
return value: | The value of an element in the array if successful, if not more of the array elements returns FALSE. |
---|---|
PHP version: | 4+ |
More examples
Example 1
All relevant presentation methods:
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>"; // The current element is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
echo current($people) . "<br>"; // Now the current element is Joe
echo prev($people) . "<br>"; // The previous element of Joe is Peter
echo end($people) . "<br>"; // The last element is Cleveland
echo prev($people) . "<br>"; // The previous element of Cleveland is Glenn
echo current($people) . "<br>"; // Now the current element is Glenn
echo reset($people) . "<br>"; // Moves the internal pointer to the first element of the array, which is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
print_r (each($people)); // Returns the key and value of the current element (now Joe), and moves the internal pointer forward
?>
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>"; // The current element is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
echo current($people) . "<br>"; // Now the current element is Joe
echo prev($people) . "<br>"; // The previous element of Joe is Peter
echo end($people) . "<br>"; // The last element is Cleveland
echo prev($people) . "<br>"; // The previous element of Cleveland is Glenn
echo current($people) . "<br>"; // Now the current element is Glenn
echo reset($people) . "<br>"; // Moves the internal pointer to the first element of the array, which is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
print_r (each($people)); // Returns the key and value of the current element (now Joe), and moves the internal pointer forward
?>
Running instance »
Complete PHP Array Reference