tobyheywood
IS-IT--Management
Hi,
I'm having a little difficulty with a multi-dimensional associative array. Basically I want to output a table which has a movie genre in bold in the first <td> and then the following <td>s will contain the movie titles themselves.
As you can tell this is a rather basic question but I would appreciate the help. I hav used the following code so far to almost acheive what I want except I cannot display the key/genre as a string it just shows as either Array or an integer.
Toby Heywood
I'm having a little difficulty with a multi-dimensional associative array. Basically I want to output a table which has a movie genre in bold in the first <td> and then the following <td>s will contain the movie titles themselves.
As you can tell this is a rather basic question but I would appreciate the help. I hav used the following code so far to almost acheive what I want except I cannot display the key/genre as a string it just shows as either Array or an integer.
Code:
<?php
$movies = array(
"SF" => array("2001", "Alien", "Terminator"),
"Comedy" => array("Happy Gilmore", "Meet the Parents", "The Nutty Professor")
);
print "<table width=60% border=\"0\">\n";
foreach ($movies as $val) {
print "<tr>";
// what can I place here to print the relative key?
foreach ($val as $key=>$movietitle) {
print "<td>$movietitle</td>\n";
}
print "</tr>";
}
print "</table>";
?>