Skip to content

Instantly share code, notes, and snippets.

@yarliganfatih
Last active April 3, 2023 12:10
Show Gist options
  • Save yarliganfatih/52160f6663c363abaedcc6c1fed0efde to your computer and use it in GitHub Desktop.
Save yarliganfatih/52160f6663c363abaedcc6c1fed0efde to your computer and use it in GitHub Desktop.
showArrayAsTable
<?php
function showArrayAsTable($array, $parent=1) {
if ($parent) {
echo "<table>";
echo "<tr>";
foreach ($array[0] as $key => $value) {
echo "<td>{$key}</td>";
}
echo "</tr>";
}
foreach ($array as $key => $value) {
if (is_array($value)) {
echo "<tr>";
showArrayAsTable($value, 0); // for childs
echo "</tr>";
} else {
echo "<td>{$value}</td>";
}
}
if ($parent) {
echo "</table>";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment