The problem of php Recursive return value

problems with recursive return values of php

ask the boss to help me look at the recursive loop lookup superiors get all the print data in the loop, but the return returns the data is empty, how is it?

    public function for_enter($data=array(),$level=0,$shu=array(),$s=0){
        $ui = M("ui");
        $array = array();
        $where["is_enter"] = 1;
        foreach ($data as $k => $v) {
            $child = $ui->where(array("code"=>$v["pcode"]))->select();
            if (empty($child)) {
                return "";
            }else{
                if ($child[0]["level"] == 4) {
                    $this->for_enter($child,$level,"");
                }else{
                    if ($child[0]["is_enter"] == 1) {
                    if (($level - $child[0]["level"]) == 3) {
                        $shu["three"] = $child[0];
                        $this->for_enter($child,$level,$shu);
                    }
                    
                    if (($level - $child[0]["level"]) == 2) {
                        $shu["tow"] = $child[0];
                        $this->for_enter($child,$level,$shu);
                    }
                    if (($level - $child[0]["level"]) == 1) {
                        //
                        $shu["one"] = $child[0];
                        $this->for_enter($child,$level,$shu);
                    }
                    }
                }
            }
            $array[] = $shu;
        }
        
        return $array;
    }

print data

clipboard.png

clipboard.png

clipboard.png

clipboard.png

Apr.09,2021

actually I saw you say that the return value was empty and I probably knew what the problem was. I looked directly at the part where you recursively called the function. If that's right, the first thing you should do is to directly enter the condition of $child [0] ['level'] = = 4, and the returned value is directly the default $shu = array ()


where you know the two values of dump clipboard.png

.
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-1b37bc5-2c0ae.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-1b37bc5-2c0ae.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?