I have this php code to form the hierarchy
$arr = array(
'name' => "Level 2: A",
'parent' => "Top Level",
'children' => ""
);
$arr2 = array(
'name' => "Top Level",
'parent' => "null",
'children' => "$arr"
);
echo json_encode($arr2);
But i cant access the array in the JSON output.
MY output from JSON: {"name":"Top Level","parent":"null","children":"Array"}
My goal is to create an array like this but with JSON but it returns as an array instead of the data inside the array
var treeData = [
{
"name": "Top Level",
"parent": "null",
"children": [
{
"name": "Level 2: A",
"parent": "Top Level",
"children": [
{
"name": "Son of A",
"parent": "Level 2: A"
},
{
"name": "Daughter of A",
"parent": "Level 2: A"
}
]
},
{
"name": "Level 2: B",
"parent": "Top Level"
}
]
} ];
'children' => "$arr"?? Should be'children' => array($arr)or'children' => $arr. Example