The example in this article describes how to read file content into an array in php. Share it with everyone for your reference. The specific analysis is as follows:
In PHP, files can be read into an array through the file() function. The elements in the array are each line of the file. The file() function uses "n" to split the file by line and save it to the array, so each of the arrays The elements all end with "n", we can remove them through the rtrim() function
<?php $lines = file("/tmp/file.txt"); foreach ($lines as $line) { $line = rtrim($line); print("$line\n"); // more statements... } ?>
I hope this article will be helpful to everyone’s PHP programming design.