I have a tree structure array of departments and I need to flatten it out into a CSV (showing the full path to each end department)
Assume I have the following array:
$arr = array("AA" => ["BB" => [], "CC" => ["DD" => [], "EE" => []]], "FF" => ["GG" =>[]]);
var_dump:
array(2) {
["AA"]=>
array(2) {
["BB"]=>
array(0) {
}
["CC"]=>
array(2) {
["DD"]=>
array(0) {
}
["EE"]=>
array(0) {
}
}
}
["FF"]=>
array(1) {
["GG"]=>
array(0) {
}
}
}
I need them flattened into a CSV structure like this
AA
AA | BB
AA | CC
AA | CC | DD
AA | CC | EE
FF
FF | GG
I have tried recursive functions but I always end up with sub arrays which wont work as CSV