PHP pos()関数
例
配列内の現在の要素の値を出力します。
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo pos($people) . "<br>";
?>
定義と使用法
pos()関数は、配列内の現在の要素の値を返します。
この関数は、current()関数のエイリアスです。
すべての配列には、その「現在の」要素への内部ポインタがあり、配列に挿入された最初の要素に初期化されます。
ヒント:この関数は、配列の内部ポインターを移動しません。
関連する方法:
- current() -配列内の現在の要素の値を返します
- end() -内部ポインタを配列の最後の要素に移動して出力します
- next() -内部ポインタを配列内の次の要素に移動して出力します
- prev() -内部ポインタを配列内の前の要素に移動して出力します
- reset() -内部ポインタを配列の最初の要素に移動します
- each() -現在の要素のキーと値を返し、内部ポインタを前方に移動します
構文
pos(array)
パラメータ値
Parameter | Description |
---|---|
array | Required. Specifies the array to use |
技術的な詳細
戻り値: | 配列内の現在の要素の値を返します。空の要素または値のない要素の場合はFALSEを返します。 |
---|---|
PHPバージョン: | 4歳以上 |
その他の例
例
関連するすべてのメソッドのデモンストレーション:
<?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
?>
❮PHP配列リファレンス