Skip to content
PHP Logo

What function can be used in PHP to read each line of a file into an array index?

To read each line of a file into an array index in PHP, you can use the file() function. This function reads the entire file into an array where each element corresponds to a line in the file. This allows you to easily access and manipulate the contents of the file line by line.

php
$lines = file('file.txt');
foreach ($lines as $line) {
    echo $line . "<br>";
}