title: php read and write file
body: <pre><code>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 &gt;= 0; $x--)
      {
        $table = explode(",", $monthNumArr[$x]);
        fwrite($fileWriter, $row[$x]);
      }
      fclose($fileWriter);
  }
  </code></pre>
  
  <p>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. </p>
  
  <p>These are the requirements:</p>
  
  <p>This function should use PHP array to store records (each line is a "record").</p>
  
  <p>This function should use a PHP Loop to walk through the months names array and generate HTML5/CSS to display the table.</p>
  
  <p>Create a function that writes the text file filewr.txt (reverse order).</p>
  
  <p>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.</p>
  
  <p>and also the txt file looks like this:</p>
  
  <pre><code>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
  </code></pre>