$$I have a bunch fo text files I'd like to eventually explode into arrays, but since the amount of text files is dynamically chosen via user input, I can't just initialize them one-by-one and instead am opting for a for loop.
For the sake of example, three text files I have contain the following (excuse the \n, imagine it's a line break):
file1.txt = 1 \n 2 \n 3
file2.txt = 6 \n 2 \n 7
file3.txt = 9 \n 1 \n 9
The code I attempted:
<?php
for ($i = 1; $i <= 3; $i++) {
list($line1[$i], $line2[$i], $line3[$i]) = file("public_html/texts/file".$i.".txt");
?>
This obviously doesn't work, but I'm not sure why. In the end, the result should be:
$line1[1] = 1
$line2[1] = 2
$line3[1] = 3
$line1[2] = 6
$line2[2] = 2
$line3[2] = 7
$line1[3] = 9
$line2[3] = 1
$line3[3] = 9
How do I go about doing this?
edit; fixed typo.