Dear friends,help me please,i have a php array,how would i display table out of it,something went wrong :

        <?php
          $data = array( 
            array ( "Hartsfield Jackson Atlanta International","Atlanta" , "ATL" ),
            array ( "Chicago O'Hare International", " Chicago", " ORD" ),
            array ("Los Angeles International", " Los Angeles", " LAX" ),
            array ( "Dallas Fort Worth International", " Dallas-Fort Worth", " DFW" ),
            array (" Denver International", " Denver", " DEN" ),
            array ( "John F Kennedy International", " New York", " JFK" ),
            array ( "San Francisco International", " San Francisco", " SFO" ),
            array ("Charlotte Douglas International", " Charlotte"," CLT" ),
            array (" McCarran International", " Las Vegas"," LAS "),
            array ("Phoenix Sky Harbor International", " Phoenix", " PHX" ),



        );
          echo "<table>
          echo <tr><th>Airport</th><th>City</th><th>Code</th></tr>";
          for ($row = 0; $row <10; $row++) {
              echo"<tr>";
                  for ($col = 0; $col < 10; $col++) {
                echo"<td>".$data[$row][$col]."</td>";
}
echo "</tr>\n";

}
          echo "</table>";
?>        

If your code example here is the same as your actual code you have several problems.
Line 17:
echo "<table>";
Line 18:
echo "<tr><th>Airport</th><th>City</th><th>Code</th></tr>";
Line 21: your inner arrays only have 3 items so you don't need to loop to 10
for ($col = 0; $col < 10; $col++) {
And, lastly, you don't have a closing </tr> inside you col loop, which is probably making your table present itself in a way you don't intend.

Line 12 - wrong syntax comma after last element of array

Hello AndrisP, although a bad practice , PHP accepts a comma after the last element of an array. Maybe bad code indentation made you miss line 16. That same bad code indentation maybe confused hericles , the “</tr>” has no reason to be inside the “col” loop but inside the “row” loop as it is (I thought it also for a moment). The main reason is line 21 and that there isn't 10 columns , I would strongly suggest using a view layer abstraction for such common things.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.