function readWrite() {
$fileReader = fopen('file.txt', 'r') or die("ERROR: File not found");
$fileWriter = fopen('filewr.txt', 'w') or die ("ERROR: Write File not
found");
$totalDaysArr= array();
$monthNumArr= array();
$monthArr= array();
$row= file("file.txt");
while($row = fgets($fileReader, 4096)) {
list($monthNumArr[], $monthArr[], $totalDaysArr[]) = explode(",", $row);
}
for($x = 11; $x >= 0; $x--)
{
$table = explode(",", $monthNumArr[$x]);
fwrite($fileWriter, $row[$x]);
}
fclose($fileWriter);
}
I'm a beginner at PHP, so this is what I have so far. My objective is to make a function that will read a file called file.txt and then write it in reverse using arrays. I'm not sure what I am doing wrong here.
These are the requirements:
This function should use PHP array to store records (each line is a "record").
This function should use a PHP Loop to walk through the months names array and generate HTML5/CSS to display the table.
Create a function that writes the text file filewr.txt (reverse order).
This function should use PHP for loop to walk through the array in reverse order and write each array entry (line/record) to the filewr.txt file.
and also the txt file looks like this:
1,January,31
2,February,28
3,March,31
4,April,30
5,May,31
6,June,30
7,July,31
8,August,31
9,September,30
10,October,31
11,November,30
12,December,31