<?php
0=>array('id'=>1, 'nome'=>'Administrador'), 0=>array('id'=>17, 'nome'=>'Administrador > Revenda 1'), 0=>array('id'=>20, 'nome'=>'Administrador > Revenda 1 > Revenda Teste > 1'), 0=>array('id'=>25, 'nome'=>'Administrador > Revenda 1 > Revenda Teste > 1 > Revenda Teste 2 - 1'), ),
2=>array('id'=>20, 'nome'=>'Administrador > Revenda 1 > Revenda Teste > 2'), 3=>array('id'=>20, 'nome'=>'Administrador > Revenda 1 > Revenda Teste > 3'), ),
),
);
foreach ($array_base as $resultado) {
if(isset($resultado['id'])){ $array_final[]= $resultado;
}else{
$array_final = subnivel($resultado, $array_final);
}
}
function subnivel($array_subnivel, $array_final){
foreach ($array_subnivel as $subnivel) {
if(isset($subnivel['id'])){ $array_final[]= $subnivel;
}else{
$array_final = subnivel($subnivel, $array_final);
}
}
return $array_final;
}
?>
PD9waHAKCSRhcnJheV9iYXNlID0gYXJyYXkoCgkJMD0+YXJyYXkoJ2lkJz0+MSwgJ25vbWUnPT4nQWRtaW5pc3RyYWRvcicpLAoJCTE9PmFycmF5KAoJCQkwPT5hcnJheSgnaWQnPT4xNywgJ25vbWUnPT4nQWRtaW5pc3RyYWRvciA+IFJldmVuZGEgMScpLAoJCQkxPT5hcnJheSgKCQkJCTA9PmFycmF5KCdpZCc9PjIwLCAnbm9tZSc9PidBZG1pbmlzdHJhZG9yID4gUmV2ZW5kYSAxID4gUmV2ZW5kYSBUZXN0ZSA+IDEnKSwKCQkJCTE9PmFycmF5KAoJCQkJCTA9PmFycmF5KCdpZCc9PjI1LCAnbm9tZSc9PidBZG1pbmlzdHJhZG9yID4gUmV2ZW5kYSAxID4gUmV2ZW5kYSBUZXN0ZSA+IDEgPiBSZXZlbmRhIFRlc3RlIDIgLSAxJyksCgkJCQkpLAoJCQkJMj0+YXJyYXkoJ2lkJz0+MjAsICdub21lJz0+J0FkbWluaXN0cmFkb3IgPiBSZXZlbmRhIDEgPiBSZXZlbmRhIFRlc3RlID4gMicpLAoJC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