How can file() be used to read a file line by line in PHP?

To read a file line by line in PHP, you can use the file() function which reads the entire file into an array where each element represents a line of the file. You can then loop through this array to process each line individually.

$filename = 'example.txt';
$lines = file($filename);

foreach ($lines as $line) {
    echo $line;
}