I\'m working on a simple CMS for a pet project. I currently have a JSON string that contains a list of page ID\'s and Parent page ID\'s for a menu structure.
I want to n
3,
'children' => array(
'id' => 4,
'children' => array(
'id' => 5,
)
)
));
array_push($json_array, array('id' => 6));
array_push($json_array, array('id' => 2));
array_push($json_array, array('id' => 4));
//your json object
$json_object = json_encode($json_array);
//echo $json_object;
//here is where you decode your json object
$json_object_decoded = json_decode($json_object,true);
//for debug to see how your decoded json object looks as an array
/*
echo "";
print_r($json_object_decoded);
echo "
";
*/
echo "";
foreach($json_object_decoded as $node){
if(isset($node['id'])){
echo "- " . $node['id'];
if(isset($node['children'])){
echo "
";
echo "- " . $node['children']['id'] . "
";
if(isset($node['children'])){
echo "";
echo "- " . $node['children']['children']['id'] . "
";
echo "
";
}
echo "
";
}
echo " ";
}
}
echo "
";
?>