With PHP, how can I make a table that uses generic references to key values instead of specific keys? I use the table, at the bottom of question, code with the array below. However, I want to use the same table code for any array (different keys and different number of keys). Any suggestions will be greatly appreciated.
Example array that is hardcoded into the PHP table code:
{
"port": "Et2",
"name": "**Description**",
"status": "connected",
"vlan": "in",
"duplex": "Po301",
"speed": "full",
"type": "10G 10GBASE-CR "
},
I would like the table code to work for any generic array such as the one below. Also not a value could be another array. I the case a value is an array, I would like all the contents of the array in one table cell even if it needs to wrap to the next line. There could be 100's of values in the array.
{
"key1": "value 1",
"key2": "value 2",
"key3": "value 3",
"key4": ["value 1a","value 2a","value 3a"]
},
I am currently using the following code to take the elements of the specific array and put it into a table but want to use table code that works for output for many network commands.
for($i = 0; $i < sizeof($data); $i++)
{
$temp .= "<tr>";
$temp .= "<td>" . $data[$i]["port"] . "</td>";
$temp .= "<td>" . $data[$i]["name"] . "</td>";
$temp .= "<td>" . $data[$i]["status"] . "</td>";
$temp .= "<td>" . $data[$i]["vlan"] . "</td>";
$temp .= "<td>" . $data[$i]["duplex"] . "</td>";
$temp .= "<td>" . $data[$i]["speed"] . "</td>";
$temp .= "<td>" . $data[$i]["type"] . "</td>";
$temp .= "</tr>";
}
/*End tag of table*/
$temp .= "</table>";
/*Printing temp variable which holds table*/
echo $temp;