I have a multidimendional array that I want to transform to a Modified Pre-order Traversal Tree:
$data = array(
"MTGO" => array("Magic Online" => array("MTGO Masters Edition", "MTGO Masters Edition II", "MTGO Masters Edition III", "MTGO Masters Edition IV")),
"Expansions" => array("Ice Age Cycle" => array("Coldsnap Theme Decks", "Ice Age", "Alliances"), "Theros" => array("Theros")),
"unclassified" => array("Portal", "Eight Edition")
);
I've tried by looping through the nested arrays, or using iterators, but I just didn't succeeded in getting the right bound.
Here what I have for getting left bound, how do I get the right one ??
foreach ($data as $groupname => $group) {
echo $i.':'.$groupname . '<br/>';
if (is_array($group)) {
foreach ($group as $blockname => $block) {
$i++;
if (is_array($block)) {
echo " " .$i.':'. $blockname . '<br/>';
foreach ($block as $setname) {
$i++;
echo " " .$i.':'. $setname . '<br/>';
}
} else {
echo " " .$i.':'. $block . '<br/>';
}
}
}
$i++;
}
Finally I've found a solution, for my needs so it goes 3 level deep, but it can be easily adapted to recursive needs with some tweaks: