I have a text file and I want each line to be an element of an array.
$file = file("books.txt");
$split = explode("\n", $file);
Then if I try to print an element of the array:
echo "$split[0]";
I get no output.
I have a text file and I want each line to be an element of an array.
$file = file("books.txt");
$split = explode("\n", $file);
Then if I try to print an element of the array:
echo "$split[0]";
I get no output.
Because file("books.txt")
gives already an array resulting from exploding by newline, you can echo "$file[0]";
, no need for further exploding.