How can the file() function in PHP be used to read the contents of a file?

To read the contents of a file in PHP, you can use the file() function. This function reads a file into an array, with each element of the array representing a line from the file. You can then loop through the array to access and process the contents of the file.

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

foreach($lines as $line) {
    echo $line . "<br>";
}