I need to put this array
all on the same level, I tried that way, but I could not leave everyone at the same level, below the input, output and code I tried.
Entry
[
(int) 0 => [
'id' => (int) 1,
'nome' => 'Administrador'
],
(int) 1 => [
(int) 0 => [
'id' => (int) 17,
'nome' => 'Administrador > Revenda 1'
],
(int) 1 => [
(int) 0 => [
'id' => (int) 20,
'nome' => 'Administrador > Revenda 1 > Revenda Teste > 1'
],
(int) 1 => [
(int) 0 => [
'id' => (int) 25,
'nome' => 'Administrador > Revenda 1 > Revenda Teste > 1 > Revenda Teste 2 - 1'
]
],
(int) 2 => [
'id' => (int) 21,
'nome' => 'Administrador > Revenda 1 > Reventa Teste > 2'
],
(int) 3 => [
'id' => (int) 22,
'nome' => 'Administrador > Revenda 1 > Revenda Teste > 3'
]
]
]
]
I need this output:
[
(int) 0 => [
'id' => (int) 1,
'nome' => 'Administrador'
],
(int) 1 => [
'id' => (int) 17,
'nome' => 'Administrador > Revenda 1'
],
(int) 2 => [
'id' => (int) 20,
'nome' => 'Administrador > Revenda 1 > Revenda Teste > 1'
],
(int) 3 => [
'id' => (int) 25,
'nome' => 'Administrador > Revenda 1 > Revenda Teste > 1 > Revenda Teste 2 - 1'
],
(int) 4 => [
'id' => (int) 21,
'nome' => 'Administrador > Revenda 1 > Reventa Teste > 2'
],
(int) 5 => [
'id' => (int) 22,
'nome' => 'Administrador > Revenda 1 > Revenda Teste > 3'
]
]
My code:
public function organizarMenu($menu){
foreach($menu as $key => $val){
if(isset($val["id"])){
$newmenu[] = ['id' => $val['id'], 'nome' => $val['nome']];
}else{
$newmenu[] = $this->organizarMenu($val);
}
}
return $newmenu;
}