(PHP 5 >= 5.1.0, PHP 7, PHP 8)
SplFileObject::current — 取得檔案目前行
此函數沒有參數。
取得檔案的目前行。如果設定了 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: ?>