Last active
April 3, 2023 12:10
-
-
Save yarliganfatih/52160f6663c363abaedcc6c1fed0efde to your computer and use it in GitHub Desktop.
showArrayAsTable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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