What are the potential pitfalls of splitting a text file into arrays in PHP?

Potential pitfalls of splitting a text file into arrays in PHP include memory consumption and performance issues, especially with large files. To mitigate these risks, consider reading the file line by line instead of loading the entire contents into memory at once. This approach can help improve efficiency and prevent memory overflows.

$file = fopen('file.txt', 'r');
$array = array();

if ($file) {
    while (($line = fgets($file)) !== false) {
        $array[] = $line;
    }
    fclose($file);
}