I'm having an issue with formatting JSON data for the jQuery JsTree. I've many children item that I'd like to show under the Root folder. However, when I can't figure out how to loop through all children item. The following code only prints 1 item from the children array. I'd like to print all the children item.
$children = [];
foreach ($items as $item) {
$children['id'] = $item['id'];
$children['text'] = $item['title'];
}
$data = [
'id' => 1,
'text' => 'Root',
'children' => $children
];
echo json_encode($data);
The above code print the following result:
{
"id":1,
"text":"Root",
"children":{
"id":"0B_J9f9IAYIKQczFkUERDUHpBYmc",
"text":"Complete Thesis.doc"
}
}