I would like to explode an array to another array based on a key.
For example :
[
{
"key": "menu.company.footer",
"content": "this is an example"
},
{
"key": "menu.company.home.foo",
"content": "bar"
}
]
Would become:
[
{
"menu":
{
"company":
{
"footer": "this is an example"
}
}
},
{
"menu":
{
"company":
{
"home":
{
"foo": "bar"
}
}
}
}
]
Here is what I have done:
- Done a
foreach
through my array - Explode the key
- Done a for with the count of the explode
My question is how create the parent/children system dynamically because I don't know how many level there will have.