-1

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.

Marco Menardi
  • 481
  • 6
  • 20

1 Answers1

2

Because file("books.txt") gives already an array resulting from exploding by newline, you can echo "$file[0]";, no need for further exploding.

n-dru
  • 9,285
  • 2
  • 29
  • 42