PHPのPOS()関数
例
出力電流の配列要素値:
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo pos($people) . "<br>";
?>
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo pos($people) . "<br>";
?>
実行中のインスタンス»
定義と使用法
POS()関数は、配列内の現在の要素の値を返します。
この関数は、 現在の()のエイリアス機能。
各アレイは、その「現在」の要素は、配列の最初の要素に挿入する最初のポイントへの内部ポインタを持っています。
ヒント:この関数は、内部配列ポインタを移動しません。
関連するメソッド:
- 現在() -配列内の現在の要素の値を返します。
- エンド() -配列、および出力の最後の要素への内部ポインタ。
- 次の() -配列、および出力の次の要素への内部ポインタ。
- PREV() -配列、および出力の最後の要素への内部ポインタ。
- RESET() -内部の配列の最初の要素へのポインタ、および出力。
- 各() -現在の要素のキー名と値を返し、内部ポインタが前進します。
文法
pos( 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の配列参照