I'm new to this and I'm trying to make a recursive function in php
public function recursive_tree($valor) {
$consulta = $this->Modelo->Getdata('getHijos', $valor);
if ($consulta->num_rows() > 0) {
foreach ($consulta->result() as $p) {
$arbol[] = array("id_user" => $p->id_user, "nombre" => $p->nombre, "id_raiz" => $p->id_raiz);
$this->recursive_tree($p->id_user);
}
echo json_encode($arbol);
}
}
, I get all the data I need but the answer is
[{"id_user":"31","nombre":"lorena","id_raiz":"29"},
{"id_user":"32","nombre":"pedro","id_raiz":"29"}]
[{"id_user":"33","nombre":"juan","id_raiz":"30"},
{"id_user":"34","nombre":"jose","id_raiz":"30"},],
as two different objects, what I try to obtain is to unite both.
[{"id_user":"31","nombre":"lorena","id_raiz":"29"},{"id_user":"32","nombre":"pedro","id_raiz":"29"},
{"id_user":"33","nombre":"juan","id_raiz":"30"},{"id_user":"34","nombre":"jose","id_raiz":"30"},]
I hope I expressed myself well and thank you for your help.