I have a PHP array that looks like this:
Array
(
[0] => Array
(
[id] => 2
[name] => Item2
[children] => Array
(
[0] => Array
(
[id] => 1
[name] => Item1
[children] => Array
(
[0] => Array
(
[id] => 5
[name] => Item5
)
)
)
[1] => Array
(
[id] => 4
[name] => Item4
)
)
)
[1] => Array
(
[id] => 3
[name] => Item3
)
)
It has unknown (unpredictable) depth and length. Any item on any level may or may not have children. It has been created from an xml file that contains product groups. I would like to convert it to an array that contains arrays of three elements: id, name, and parent id:
[0] => array('id' => '2', 'name' => 'Item2', 'parent' => 0),
[1] => array('id' => '1', 'name' => 'Item1', 'parent' => 2),
[2] => array('id' => '4', 'name' => 'Item4', 'parent' => 2) etc.
How can I do it? Thank you!