PHP各()関数
例
現在の要素のキー名と値を返し、内部ポインタが前方に移動します。
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
print_r (each($people));
?>
$people = array("Peter", "Joe", "Glenn", "Cleveland");
print_r (each($people));
?>
実行中のインスタンス»
定義と使用法
各()関数は、現在の要素のキー名と値を返し、内部ポインタが前進します。
4つの重要な要素を持つ配列の名前とリターンの重要な要素。 二つの要素(1と値)はキーが含まれている2つの要素(0とキー)キー名が含まれています。
関連するメソッド:
- 現在() -配列内の現在の要素の値を返します。
- エンド() -配列、および出力の最後の要素への内部ポインタ。
- 次の() -配列、および出力の次の要素への内部ポインタ。
- PREV() -配列、および出力の最後の要素への内部ポインタ。
- RESET() -内部の配列の最初の要素へのポインタ、および出力。
文法
each( array )
参数 | 描述 |
---|---|
array | 必需。规定要使用的数组。 |
技術的詳細
戻り値: | 現在の要素のキー名と値を返します。 4つの重要な要素を持つ配列の名前とリターンの重要な要素。 二つの要素(1と値)はキーが含まれている2つの要素(0とキー)キー名が含まれています。 配列にそれ以上の要素がない場合、この関数はFALSEを返します。 |
---|---|
PHPバージョン: | 4+ |
より多くの例
例1
同じページの上部にある例が、出力配列のサイクル全体を通じて、この場合には:
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
reset($people);
while (list($key, $val) = each($people))
{
echo "$key => $val<br>";
}
?>
$people = array("Peter", "Joe", "Glenn", "Cleveland");
reset($people);
while (list($key, $val) = each($people))
{
echo "$key => $val<br>";
}
?>
実行中のインスタンス»
例2
関連するすべてのプレゼンテーションの方法:
<?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の配列参照