i have an array thats it a result from the db query, and i want to make a tree structure based on it.
I am using php, maybe its need a recursive function, but i dont have any ideia how to do it.
here is my array of data:
Array
(
[0] => Array
(
[nome] => adicionar
[sub_funcao] => sub_funcao
[nome_funcao] =>
[tipo_sub_funcao] => 3
[check_dropdown] =>
[posicao] => 1
[dropdown_id] => 1
[dropdown_where] =>
[pagina] => ddc_funcoes
)
[1] => Array
(
[nome] => drop teste 1
[sub_funcao] => sub_funcao
[nome_funcao] => teste
[tipo_sub_funcao] => 3
[check_dropdown] =>
[posicao] => 5
[dropdown_id] => 1.1
[dropdown_where] => 1
[pagina] => ddc_funcoes
)
[2] => Array
(
[nome] => deletar
[sub_funcao] => sub_funcao
[nome_funcao] => funcoes_deletar[sub_funcao]
[tipo_sub_funcao] => 1
[check_dropdown] =>
[posicao] => 3
[dropdown_id] => 3
[dropdown_where] =>
[pagina] => ddc_funcoes
)
[3] => Array
(
[nome] => editar
[sub_funcao] => sub_funcao
[nome_funcao] => funcoes_editar[sub_funcao]
[tipo_sub_funcao] => 1
[check_dropdown] =>
[posicao] => 2
[dropdown_id] => 2
[dropdown_where] =>
[pagina] => ddc_funcoes
)
[4] => Array
(
[nome] => sub funcao teste 1
[sub_funcao] => sub_funcao
[nome_funcao] => teste
[tipo_sub_funcao] => 1
[check_dropdown] =>
[posicao] => 4
[dropdown_id] =>
[dropdown_where] => 1
[pagina] => ddc_funcoes
)
[5] => Array
(
[nome] => sub funcao teste 2
[sub_funcao] => sub_funcao
[nome_funcao] => teste
[tipo_sub_funcao] => 1
[check_dropdown] =>
[posicao] => 1
[dropdown_id] =>
[dropdown_where] => 1.1
[pagina] => ddc_funcoes
)
[6] => Array
(
[nome] => sub funcao
[sub_funcao] => sub_funcao
[nome_funcao] => funcoes_adicionar[sub_funcao]
[tipo_sub_funcao] => 1
[check_dropdown] => adicionar
[posicao] => 1
[dropdown_id] =>
[dropdown_where] => 1
[pagina] => ddc_funcoes
)
[7] => Array
(
[nome] => sub funcao dropdown
[sub_funcao] => sub_funcao
[nome_funcao] => funcoes_adicionar[sub_funcao_dropdown]
[tipo_sub_funcao] => 1
[check_dropdown] => adicionar
[posicao] => 3
[dropdown_id] =>
[dropdown_where] => 1
[pagina] => ddc_funcoes
)
[8] => Array
(
[nome] => sub funcao tab
[sub_funcao] => sub_funcao
[nome_funcao] => funcoes_adicionar[sub_funcao_tab]
[tipo_sub_funcao] => 1
[check_dropdown] => adicionar
[posicao] => 2
[dropdown_id] =>
[dropdown_where] => 1
[pagina] => ddc_funcoes
)
)
what i am trying to achieve here is dropdown_id is the head of the level and dropdown_where is where it should go.
for example, dropdown_id = 1 will receive dropdown_where = 2, and if its level 2, dropdown_id = 1.1 will receive dropdown_where = 1.1.
Dont have any ideia if is right to do this way, so i will be glad with some advices
Expected output:
Array
(
[0] => Array
(
[nome] => adicionar
[sub_funcao] => sub_funcao
[nome_funcao] =>
[tipo_sub_funcao] => 3
[check_dropdown] =>
[posicao] => 1
[dropdown_id] => 1
[dropdown_where] =>
[pagina] => ddc_funcoes
[sub_funcao_arr] => Array
(
[0] => Array
(
[nome] => sub funcao
[sub_funcao] => sub_funcao
[nome_funcao] => funcoes_adicionar[sub_funcao]
[tipo_sub_funcao] => 1
[check_dropdown] => adicionar
[posicao] => 1
[dropdown_id] =>
[dropdown_where] => 1
[pagina] => ddc_funcoes
)
[1] => Array
(
[nome] => sub funcao dropdown
[sub_funcao] => sub_funcao
[nome_funcao] => funcoes_adicionar[sub_funcao_dropdown]
[tipo_sub_funcao] => 1
[check_dropdown] => adicionar
[posicao] => 3
[dropdown_id] =>
[dropdown_where] => 1
[pagina] => ddc_funcoes
)
[2] => Array
(
[nome] => sub funcao tab
[sub_funcao] => sub_funcao
[nome_funcao] => funcoes_adicionar[sub_funcao_tab]
[tipo_sub_funcao] => 1
[check_dropdown] => adicionar
[posicao] => 2
[dropdown_id] =>
[dropdown_where] => 1
[pagina] => ddc_funcoes
)
[3] => Array
(
[nome] => sub funcao teste 1
[sub_funcao] => sub_funcao
[nome_funcao] => teste
[tipo_sub_funcao] => 1
[check_dropdown] =>
[posicao] => 4
[dropdown_id] =>
[dropdown_where] => 1
[pagina] => ddc_funcoes
)
[4] => Array
(
[nome] => drop teste 1
[sub_funcao] => sub_funcao
[nome_funcao] => teste
[tipo_sub_funcao] => 3
[check_dropdown] =>
[posicao] => 5
[dropdown_id] => 1.1
[dropdown_where] => 1
[pagina] => ddc_funcoes
[dropdown] => Array
(
[0] => Array
(
[nome] => sub funcao teste 2
[sub_funcao] => sub_funcao
[nome_funcao] => teste
[tipo_sub_funcao] => 1
[check_dropdown] =>
[posicao] => 1
[dropdown_id] =>
[dropdown_where] => 1.1
[pagina] => ddc_funcoes
)
)
)
)
)
[1] => Array
(
[nome] => editar
[sub_funcao] => sub_funcao
[nome_funcao] => funcoes_editar[sub_funcao]
[tipo_sub_funcao] => 1
[check_dropdown] =>
[posicao] => 2
[dropdown_id] => 2
[dropdown_where] =>
[pagina] => ddc_funcoes
)
[2] => Array
(
[nome] => deletar
[sub_funcao] => sub_funcao
[nome_funcao] => funcoes_deletar[sub_funcao]
[tipo_sub_funcao] => 1
[check_dropdown] =>
[posicao] => 3
[dropdown_id] => 3
[dropdown_where] =>
[pagina] => ddc_funcoes
)
)