How do you output a Multi Dimensional Array to a Table
Posted: Wed Feb 08, 2006 5:20 am
I am stumped on this one.
Here is an example of the array structure:
Here is an example of the array structure:
And here is the code I wrote which does not work because the $Field value is always "Array":Array
(
[0] => Array
(
[One] => 1
[Two] => 6
[Three] => 4
[Four] => 38
)
[1] => Array
(
[One] => 16
[Two] => 2
[Three] => 0
[Four] => 156
)
[2] => Array
(
[One] => 4
[Two] => 1
[Three] => 0
[Four] => 19522
)
[3] => Array
(
[One] => 5
[Two] => 1
[Three] => 1
[Four] => 0
)
)
Code: Select all
foreach ($Array as $Field) {
foreach ($Field as $Data) {
echo "<b>" . current($Field) . "</b><br />";
switch ($Field) {
case "One":
$Name = get_name($Data);
$Table .= " <tr>\n";
$Table .= " <td>$Name</td>\n";
break;
case "Two":
$Table .= " <td>$Data</td>\n";
break;
case "Three":
$Table .= " <td>$Data</td>\n";
break;
case "Four":
$Table .= " <td>$Data</td>\n";
$Table .= " <td> </td>\n";
$Table .= " </tr>";
break;
}
}
}