I have outputted the multidimensional array of directories where dimensions in depth are the subfolders.
Output
array(4) {
["tt"]=>
array(1) {
["nn"]=>
array(1) {
["fff"]=>
array(0) {
}
}
}
["testgg"]=>
array(3) {
["fff"]=>
array(0) {
}
["ggg"]=>
array(2) {
["ttttt"]=>
array(0) {
}
["kk"]=>
array(0) {
}
}
["bb"]=>
array(1) {
["ssssss"]=>
array(0) {
}
}
}
["test"]=>
array(3) {
["dd"]=>
array(0) {
}
["ew"]=>
array(1) {
["re"]=>
array(1) {
["ffff"]=>
array(0) {
}
}
}
["hh"]=>
array(0) {
}
}
["eeeee"]=>
array(2) {
["fff"]=>
array(1) {
["test"]=>
array(2) {
[0]=>
string(30) "Save-Image-File-Formats-2a.png"
["nnn"]=>
array(1) {
["bbb"]=>
array(0) {
}
}
}
}
["sss"]=>
array(0) {
}
}
}
I need to make all the keys into a string in the format below
Format
{
text: "Parent 1",
nodes: [
{
text: "Child 1",
nodes: [
{
text: "Grandchild 1"
},
{
text: "Grandchild 2"
}
]
},
{
text: "Child 2",
test: "hell yea"
}
]
},
{
text: "Parent 2"
},
{
text: "Parent 3"
},
{
text: "Parent 4"
},
{
text: "Parent 5"
}
Where the child nodes represent the subfolders.
How can I implement a recursive function to convert the array into a string with the above format?