- array_keys: documentation ( source)
<?php
// price matrix: first index is y-axis, second is x-axis
$prices = [
600 => [
600 => 224,
700 => 246,
800 => 266,
900 => 291,
1000 => 313
],
// here you put the rest...
];
//then echo the table;
echo "<table><tr>";
echo "<td></td>"; // first empty cell;
foreach ($prices[array_keys($prices)[0]] as $y_axis => $xprices){
echo "<td>".$y_axis."</td>";
}
echo "</tr>";//finish setting up the header
foreach ($prices as $y_axis => $xprices) {
echo "<tr>";
echo "<td>".$y_axis."</td>";
foreach($xprices as $y_axis=> $price){
echo "<td>".$price."</td>";
}
echo "</tr>";
}
echo "</table>";