I'm trying to create an array - in - array structure based on the value of each of the entries and I don't really know how I should approach this.
I hope someone from SO can help me achieve it efficiently.
Things I have tried until now: Setting parents and appending children, then doing the same for each of the children.
Input:
array(
array('value' => 0),
array('value' => 4),
array('value' => 4),
array('value' => 8),
array('value' => 0),
array('value' => 4)
)
Wanted Output
array(
array('value' => 0
'children' => array(
array('value' => 4),
array('value' => 4
'children' => array(
array('value' => 8)
)
)
)
),
array('value' => 0
'children' => array(
array('value' => 4)
)
)
)
I'd appreciate any ideas. I'm thinking of a recursive method to achieve this, however I don't know how to do it properly.
Thank you very much in advance!