Array inside Array - d3.tree data

0

I'm building an array in the format valid for the d3-tree chart. For this, I have the data in the following format: Data column and data name of the Main Company. Example:

Main Company
Column-Name
1-Company A 1.1-Company A.a
1.1.1-Company A.a.a
1.1.2-Company A.a.b
1.1.2.1-Company A.a.b.a
1.2-Company A.b
1.2.1-Company A.b.a
For now, I initialized an object of class with the first entry and made a function that receives the column and the name:
$ this- > Dataset_dd3 = array ("name" = > "Parent Company");
private function Insert_Children ($ company_name, $ column) {

    $aux = explode('.',$coluna);
    if(count($aux)==1) $this->Dados_grafico_d3["children"][]=array("name"=>$nome_empresa);
    if(count($aux)==2){
        $aux[0]=$aux[0]-1;
        $this->Dados_grafico_d3["children"][$aux[0]]["children"][]=array("name"=>$nome_empresa);    
    }
    if(count($aux)==3){
        $aux[0]=$aux[0]-1;
        $aux[1]=$aux[1]-1;
        $this->Dados_grafico_d3["children"][$aux[0]]["children"][$aux[1]]["children"][]=array("name"=>$nome_empresa);     
    }
}

It works perfectly this way on a case-by-case basis, the problem is that I have infinite cases and can reach different columns and can not do case by count. Could someone help?

    
asked by anonymous 25.07.2018 / 09:13

0 answers