What are the potential pitfalls of using the file() function in PHP to read a text file into an array?
Using the file() function in PHP to read a text file into an array can potentially result in memory issues if the file is too large. To avoid this, it is recommended to use the fopen() function along with fgets() to read the file line by line instead of loading the entire file into memory at once.
$file = fopen('example.txt', 'r');
$lines = [];
while (!feof($file)) {
$lines[] = fgets($file);
}
fclose($file);