-1
I need to put this array
all on the same level, I tried that way, but I couldn’t leave everyone on the same level, it goes down the input, output and the code I tried.
Entree
[
(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 exit:
[
(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;
}
"but something is missing" what’s missing?
– Costamilam
Missing the way out.
– Laercio Nunes
I understood the question. See my answer if you answer.
– David Alves