PHPのリセット()関数
例
配列要素の出力と次の要素の電流値は、その配列の最初の要素に内部配列ポインタをリセットします。
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>";
echo next($people) . "<br>";
echo reset($people);
?>
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>";
echo next($people) . "<br>";
echo reset($people);
?>
実行中のインスタンス»
定義と使用法
内部配列の最初の要素へのポインタ、および出力の()関数をリセットします。
関連するメソッド:
- 現在() -配列内の現在の要素の値を返します。
- エンド() -配列、および出力の最後の要素への内部ポインタ。
- 次の() -配列、および出力の次の要素への内部ポインタ。
- PREV() -配列、および出力の最後の要素への内部ポインタ。
- 各() -現在の要素のキー名と値を返し、内部ポインタが前進します。
文法
reset( 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の配列参照