title: PHP display associative array in HTML table
body: <p>Here is my associative array:</p>
  
  <pre><code>$req_data1[]=array(
      'depart1'=&gt;$_REQUEST['to'],
      'd_time1'=&gt;$d_time5,
      'stop'=&gt;"",
      'leave_stop'=&gt;"",
      'arrival1'=&gt;$_REQUEST['from'],
      'a_time1'=&gt;$end_time5,
      'price1'=&gt;intval($final_price),
      'air_line'=&gt;"xxxxx");
  </code></pre>
  
  <p>Here is my sorting algorithm:</p>
  
  <pre><code>foreach ($req_data as $key =&gt; $row) {
      $depart[$key]  = $row['depart'];
      $d_time[$key] = $row['d_time'];
      $stop[$key]  = $row['stop'];
      $leave_stop[$key] = $row['leave_stop'];
      $arrival[$key]  = $row['arrival'];
      $a_time[$key] = $row['a_time'];
      $price[$key] = $row['price'];
  }
  
  array_multisort($price,SORT_ASC, $req_data);
  </code></pre>
  
  <p>I am displaying the data after sorting:</p>
  
  <pre><code>foreach($req_data as $key=&gt;$row) {
      echo "&lt;/br&gt;";
  
      foreach($row as $key2=&gt;$row2){
          echo $row2;
      }
  }
  </code></pre>
  
  <p>My problem now is that I want to put that array into an HTML table but dont know how. This is my code which I tried so far but its not working:</p>
  
  <pre><code>$cols = 5; 
  
  echo "&lt;table border=\"5\" cellpadding=\"10\"&gt;"; 
  
  for ($r=0; $r &lt; count($row2); $r++) { 
      echo "&lt;tr&gt;"; 
  
      for ($c=0; $c&lt;$cols; $c++) { 
  
          ?&gt; &lt;td&gt; &lt;?php $input[$r+$c] ?&gt; &lt;/td&gt; &lt;?php 
          }
  
      echo "&lt;/tr&gt;"; 
      $r += $c; 
  }
  
  echo "&lt;/table&gt;";
  ?&gt;
  </code></pre>
  
  <p>Could any one tell me what is wrong with my code, or how I can display this sorted data into a table? Thanks.</p>