The following code will look at two dimensions of the array and turn them into a table. No matter what the key
may be, you get a visual representation of this. If they do have a key name, not just an index, the values will be available in $key
and $subkey
respectively. Therefore, you have them if you need them.
The code:
$myarray = array("key1"=>array(1,2,3,4), "key2"=>array(2,3,4,5), "key3"=>array(3,4,5,6), "key4"=>array(4,5,6,7));
Result:
If you want to see the keys as headers, you can add this code after the line echo "<table>";
:
echo "<tr>"; foreach($myarray as $key => $element) echo "<td>$key</td>"; echo "</tr>";
As a result:
source share