I'm trying to create a recursive array based on string's length : string length is the level of the node. This is actually to build a treeview on Yii framework. Here comes an example...
I've a list of strings :
Array
(
[0] => A
[1] => C
[2] => CC
[3] => CCC
[4] => P
[5] => PP
[6] => PPP
[7] => PPPE
[8] => PS
[9] => PSA
)
And I want to sort them like that :
Array
(
[0] => Array
(
[text] => A
)
[1] => Array
(
[text] => C
[children] => Array
(
[0] => Array
(
[text] => CC
[children] => Array
(
[0] => Array
(
[text] => CCC
)
)
)
)
)
[2] => Array
(
[text] => P
[children] => Array
(
[0] => Array
(
[text] => PP
[children] => Array
(
[0] => Array
(
[text] => PPP
[children] => Array
(
[0] => Array
(
[text] => PPPE
)
)
)
)
)
[1] => Array
(
[text] => PS
[children] => Array
(
[0] => Array
(
[text] => PSA
)
)
)
)
)
)
I know I've to figure out something with recursive functions but I just don't know how to do it, despite the fact i'm trying for days... Did somebody done something like that ? Many thanks...