I'm having trouble creating a folder-structure-like array from an array of folder.
This is an array the function receives
Array
(
[0] => Array
(
[id] => 6
[name] => 2011
[parent_folder] => 1
)
[1] => Array
(
[id] => 5
[name] => 2012
[parent_folder] => 1
)
[2] => Array
(
[id] => 7
[name] => April
[parent_folder] => 6
)
[3] => Array
(
[id] => 2
[name] => Folder2
[parent_folder] =>
)
[4] => Array
(
[id] => 1
[name] => Folder1
[parent_folder] =>
)
)
The output should be an array where subfolders are stored as arrays under the key 'content' inside their partent_folder's array
Array
(
[0] => Array
(
[id] => 2
[name] => Folder2
[parent_folder] =>
)
[1] => Array
(
[id] => 1
[name] => Folder1
[parent_folder] =>
[content] => Array
(
[0] => Array
(
[id] => 6
[name] => 2011
[parent_folder] => 1
[content] => Array
(
[0] => Array
(
[id] => 7
[name] => April
[parent_folder] => 6
)
)
)
[1] => Array
(
[id] => 5
[name] => 2012
[parent_folder] => 1
)
)
)
)
I tried around but can't get it to work. There must be a recursive way to rearrange the array. Can anybody help? Would be greatly appreciated!