If you want recursive way:
public static function jsonToDebug($jsonText = '')
{
$arr = json_decode($jsonText, true);
$html = "";
if ($arr && is_array($arr)) {
$html .= self::_arrayToHtmlTableRecursive($arr);
}
return $html;
}
private static function _arrayToHtmlTableRecursive($arr) {
$str = "<table><tbody>";
foreach ($arr as $key => $val) {
$str .= "<tr>";
$str .= "<td>$key</td>";
$str .= "<td>";
if (is_array($val)) {
if (!empty($val)) {
$str .= self::_arrayToHtmlTableRecursive($val);
}
} else {
$str .= "<strong>$val</strong>";
}
$str .= "</td></tr>";
}
$str .= "</tbody></table>";
return $str;
}
Then call echo YourClass::jsonToDebug($jsonText)
;
My test on http://sandbox.onlinephpfunctions.com/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…