Multidimensional Array to HTML Table

Hi Guys,

my below code is not working properly

Does anybody know how I format a Multidimensional Array into a HTML Table.

<?php


   $movies = array 
   (
      array('Office Space' , 'Comedy' , 'Mike Judge' ),
      array('Matrix' , 'Action' , 'Andy / Larry Wachowski' ),
      array('Lost In Translation' , 'Comedy / Drama' , 'Sofia Coppola' ),
      array('A Beautiful Mind' , 'Drama' , 'Ron Howard' ),
      array('Napoleon Dynamite' , 'Comedy' , 'Jared Hess' )
   );
   
   echo "<table border=\\"1\\">";
   echo "<tr><th>Movies</th><th>Genre</th><th>Director</th></tr>";
   for ( $row = 0; $row < count($movies); $row++ )
   {
      echo "<tr><td>";
      for ( $column = 0; $column < count($movies); $column++ )
      {
         echo $movies[$row][$column] ;
      }
      echo "<td></tr>";
   }

?>

Thanks…

I would use a foreach in this case.

http://us2.php.net/manual/en/control-structures.foreach.php


<?php
$movies = array(
    array('Office Space' , 'Comedy' , 'Mike Judge' ),
    array('Matrix' , 'Action' , 'Andy / Larry Wachowski' ),
    array('Lost In Translation' , 'Comedy / Drama' , 'Sofia Coppola' ),
    array('A Beautiful Mind' , 'Drama' , 'Ron Howard' ),
    array('Napoleon Dynamite' , 'Comedy' , 'Jared Hess' )
);

echo '<table border="1">';
echo '<tr><th>Movies</th><th>Genre</th><th>Director</th></tr>';
foreach( $movies as $movie )
{
    echo '<tr>';
    foreach( $movie as $key )
    {
        echo '<td>'.$key.'</td>';
    }
    echo '</tr>';
}
echo '</table>';
?>

Here is the easiest way to do what you’re after… but I’d like to know where you’re getting the data?

Perfect, thanks poncho.

I am just using this to learn from it. When would you use the multidimiensional array in real life anywho?