PHP 8.1.28 Released!

SplFileObject::current

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

SplFileObject::currentファイルの現在の行を取得する

説明

public SplFileObject::current(): string|array|false

ファイルの現在の行を取得します。

パラメータ

この関数にはパラメータはありません。

戻り値

ファイルの現在の行を取得します。SplFileObject::READ_CSV フラグがセットされている場合、このメソッドは CSV データとして処理された現在の行を格納している配列を返します。 ファイルの終端に達した場合、false を返します。

例1 SplFileObject::current() の例

<?php
$file
= new SplFileObject(__FILE__);
foreach (
$file as $k => $line) {
echo (
$file->key() + 1) . ': ' . $file->current();
}
?>

上の例の出力は、 たとえば以下のようになります。

1: <?php
2: $file = new SplFileObject(__FILE__);
3: foreach ($file as $line) {
4:     echo ($file->key() + 1) . ': ' . $file->current();
5: }
6: ?>

参考

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top