I have a multidimensional nested array:
$arr = array(
'name' => 'Root Node',
'children' => array(
array(
'name' => 'Node A',
'children' => array(
array(
'name' => 'Node A.1',
'children' => array(
array(
'name' => 'Node A.1.1',
'children' => ''
),
),
),
array(
'name' => 'Node A.2',
'children' => ''
),
),
),
array(
'name' => 'Node B',
'children' => array(
array(
'name' => 'Node B.1',
'children' => '',
),
array(
'name' => 'Node B.2',
'children' => ''
),
)
),
array(
'name' => 'Node C',
'children' => ''
)
),
);
Currently this array is upto 4 levels but we can't assume its depth level static to 4 as it may have N levels as well. My goal is to convert this array with individual row array per relation like:
$arr = array(
array( 'Root Node', 'Nodel A', 'Node A.1', 'Node A.1.1' ),
array( 'Root Node', 'Nodel A', 'Node A.2' ),
array( 'Root Node', 'Nodel B', 'Node B.1' ),
array( 'Root Node', 'Nodel B', 'Node B.2' ),
array( 'Root Node', 'Nodel C' ),
);
I know a recursive function should do the trick but I can't figure it out as its not that easy I thought in start. Any help would be greatly appreciated!