<?php
function printAll($a, &$output, $prefix = '') {
if (!is_array($a) && !is_object($a)) {
$prefix = rtrim($prefix, '/');
$output[] = $prefix . ' => ' . $a. "\n";
return;
}
foreach($a as $k => $v) {
$tmp = $prefix;
$tmp .= $k . "/";
printAll($v, $output, $tmp);
}
}
$json_str = '{
"one":
{
"two": 3,
"four": [ 5,6,7]
},
"eight":
{
"nine":
{
"ten":11
}
}
}';
$object = json_decode($json_str);
$res = array();
printAll($object, $res);
var_dump($res);
preferences:
24.39 ms | 406 KiB | 5 Q