Page 1 of 1
PHP Array & Grid
Posted: Tue Sep 25, 2012 4:00 pm
by dimxasnewfrozen
Code: Select all
$columns = array("C1", "C2");
$rows = array("Row1", "Row2");
I would like to be able to get a result in a table/grid
C1 | C2
Row1 | Row1C1 | Row1C2
Row2 | Row2C1 | Row2C2
I am trying to join the arrays which isn't really working well.
Code: Select all
$large_array = array();
foreach($columns as $c) {
foreach ($rows as $row)
$large_array[] = array($c => $row);
}
Re: PHP Array & Grid
Posted: Tue Sep 25, 2012 5:56 pm
by requinix
Well, you could just
Code: Select all
echo "<table><tr>";
echo "<th></th>"; // empty cell in the top-left corner
foreach ($columns as $col) {
echo "<th>{$col}</th>";
}
echo "</tr>";
foreach ($rows as $row) {
echo "<tr>";
foreach ($columns as $col) {
echo "<td>{$row} {$col}</td>";
}
echo "</tr>";
}
echo "</table>";