I need to encode a multidimensional array with e.g. CJavaScript or CJSON, but I need to avoid PHP array keys.
Assuming the following data structure
$dataTree = array(
'39'=>array(
'label' => 'node1',
'children' => array(
'42'=>array('label' => 'child1'),
'44'=>array('label' => 'child2'),
),
),
'40'=>array(
'label' => 'node2',
)
);
I would need to get the following output (in Javascript):
var data = [
{
label: 'node1',
children: [
{ label: 'child1' },
{ label: 'child2' }
]
},
{
label: 'node2',
children: [
{ label: 'child3' }
]
}
];
Is there any way to do this?