PHP current() 関数

❮ PHP 配列リファレンス

配列内の現在の要素の値を出力します:

<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");

echo current($people) . "<br>";
?>
例の実行 »

定義と用法

current()関数は、配列内の現在の要素の値を返します。

全ての配列には、現在の要素への内部ポインタを持っており、配列の最初の要素に初期化されています。

チップ: この関数は、配列の内部ポインタを移動しません。

関連するメソッド:


構文

current(array)

パラメータ 説明
array 必須。使用する配列を指定する

技術内容
返り値: 配列内の現在の要素の値を返します。空の要素または値のない要素の場合はFALSEを返します
PHP バージョン: 4+

その他の例

例 1

A demonstration of all related methods:

<?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>"; // 内部ポインタを配列の最初の要素の 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 配列リファレンス