PHP prevを()関数
例
配列内の現在の要素の出力、次の要素と値の要素:
<?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);
?>
実行中のインスタンス»
定義と使用法
最後の配列の要素、および出力にPREV()関数内部ポインタ。
関連するメソッド:
- 次の() -配列、および出力の次の要素への内部ポインタ。
- 現在() -配列内の現在の要素の値を返します。
- エンド() -配列、および出力の最後の要素への内部ポインタ。
- RESET() -内部の配列の最初の要素へのポインタ、および出力。
- 各() -現在の要素のキー名と値を返し、内部ポインタが前進します。
文法
prev( array )
参数 | 描述 |
---|---|
array | 必需。规定要使用的数组。 |
技術的詳細
戻り値: | 配列内の要素の値は、配列要素の成功、そうでない場合よりはFALSEを返します。 |
---|---|
PHPバージョン: | 4+ |
より多くの例
例1
関連するすべてのプレゼンテーションの方法:
<?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
?>
実行中のインスタンス»
完全なPHPの配列参照