PHP Code:
$lines=file('file.txt');
This loads the file into $lines, one line of text per item in the array. (info here)
PHP Code:
foreach($lines as $line) {
For each iteration of this loop, the next line is loaded into $line
$d1 is for keeping track of $bigarray's subscripts.
PHP Code:
$bigarray[$d1]=new array();
Makes $bigarray[$d1] an array itself, so that it can hold all the words.
PHP Code:
$words=explode(' ',$line);
Splits up the current line into the $words array (using a space as the delimeter).
PHP Code:
foreach($words as $word) {
For each iteration of this loop, the next word is loaded into $word
$d2 is for keeping track of $bigarray[$d1]'s subscripts.
PHP Code:
$bigarray[$d1][$d2]=$word;
Put each word in the appropriate part of $bigarray.
Increment $d2 counter ready for the next word.
Increment $d1 counter ready for the next line.
|