I have two arrays:
$array1 = array(1,2,3,4,7,6);
$array2 = array(2,3,1,0,5);
Then I tried to create printTable
function to print multiplication table for arrays:
function printTable($array1, $array2) {
echo "<table border=1px>";
foreach ($array2 as $vert_head) {
echo "<tr>";
foreach ($array1 as $hor_head) {
echo "<td>". ($vert_head * $hor_head) ."</td>";
}
echo "</tr>";
}
echo "</table>";
}
And then print table:
$data = printTable($array1, $array2);
It works fine table is print. But how can I add horizontal and vertical header from arrays?
That how my table looks right now(just answers):
2 | 4 | 6 | 8 | 14 | 12 |
3 | 6 | 9 | 12 | 21 | 18 |
1 | 2 | 3 | 4 | 7 | 6 |
0 | 0 | 0 | 0 | 0 | 0 |
5 | 10 | 15 | 20 | 35 | 30 |
How can I add headers:
| | 1 | 2 | 3 | 4 | 7 | 6 |
+---+---+----+----+----+----+----+
| 2 | 2 | 4 | 6 | 8 | 14 | 12 |
| 3 | 3 | 6 | 9 | 12 | 21 | 18 |
| 1 | 1 | 2 | 3 | 4 | 7 | 6 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 5 | 5 | 10 | 15 | 20 | 35 | 30 |