Programming ideas
The first function to use is fi1e. This function is similar to readfile(). The difference is that the file function reads all the contents of the file and outputs it to the variable of the array. Each line is a separate array element. . Use the file function to open a data.txt file. The content of the data.txt file is:
First line 1
Second line 2
Third line 3
The statement to open the file is: $myFile=file("data.txt"); at this time $myFile is an array variable.
Then use the loop instruction to loop through the array to print out the contents of each element of the array. The count() function used here is used to
Get the number of array elements. The statement to print the contents of the array is: print($myFile[$index]." ").
Creation steps
1. Use the file function to open the file
$myFile=file("data.txt");
2. Loop through the array and print the elements of the array
Here, via
for($index=0;$index
for($index=0;$index ) {
🎜>
At the same time, print out the contents of the elements in the array.
3. Program code
< ?
// Open the file and print each line
$myFile=file("data.txt");
for($index=0;$index
print($myFile&91;$index&93;."
");
}
?>