This callback is a little difficult! Create an infinite level classification tree based on an array

public function test(){
        $data = array(
            ""=>array(
                ""=>array(
                    ""=>array(
                        "ysy"=>1,
                        "tsm"=>9
                    ),
                    ""=>array(
                        "ysy"=>2,
                        "tsm"=>8
                    )
                ),
                ""=>array(
                    ""=>array(
                        ""=>3,
                        ""=>6,
                    ),
                    ""=>array(
                        ""=>4,
                        ""=>5,
                    ),
                )
            )
        );
       $result = $this->initTree($data,0,1,1);
    }
    /**
     * 
     * @param $data
     * @param $level
     * @param int $step
     * @param array $arr
     * @return int
     */
    protected function initTree($data,$pid,$level=1,$step=1,$arr=[])
    {
            foreach ($data as $k=>$v) {
                //
                $sql = "select id from srv_kit_category where pid=".$pid." and name="" . $k.""";
                $idObj = $this->dao->querySql($sql);
                $id = $idObj?$idObj[0]->id:0;

                //id
                if (!$id) {
                    $insertData = array(
                        "pid" => $pid,
                        "name" => $k,
                        "level"=>$level,
                    );
                    $this->dao->insert("srv_kit_category")->data($insertData)->check("name", "notempty")->exec();
                    if (dao::isError()) {
                       return 404;
                    }
                    $id = $this->dao->lastInsertID();//id
                }

                //idlevel
                if (is_array($v)) {
                    $arr[$step]=$id;
                    $pid = $arr[$step];
                    $stepPP;
                    $levelPP;
                }
                $this->initTree($v, $pid,$level,$step,$arr);//
                $step--;
                $level--;
            }
            return 200;

    }

the result is as follows




Php
Mar.15,2021

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3cefe-2c35e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3cefe-2c35e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?