php递归函数不返回布尔值

时间:2017-08-17 14:28:28

标签: php recursion

if [ $COMMAND_LINE_INSTALL ]; then 
    # Do stuff for CLI land
else
    # Do stuff for GUI land
fi

function check($string, $id, $type){ if($type == "edit"){ $sql = "SELECT * FROM test where first = '".$string."' and id = ".$id.""; $query = $this->db->query($sql); $array = $query->result(); if(!empty($array)){ return true; #VALID }else{ $this->check($string,NULL,"add"); } }else{ $sql = "SELECT * FROM test where name = '".$string."'"; $query = $this->db->query($sql); $array = $query->result(); if(empty($array)){ return true; }else{ return false; } } } 不会返回该值。我用boolean或string值尝试了这个。请帮忙。

1 个答案:

答案 0 :(得分:4)

function check($string, $id, $type){
    if($type == "edit"){
        $sql = "SELECT * FROM test where first = '".$string."' and id = ".$id."";
        $query = $this->db->query($sql);
        $array = $query->result();
        if(!empty($array)){
           return true; #VALID
        }else{
           return $this->check($string,NULL,"add");
        }
     }else{
         $sql = "SELECT * FROM test where name = '".$string."'";
         $query = $this->db->query($sql);
         $array = $query->result();
         if(empty($array)){ 
            return true; 
         }else{
            return false;
         }
     }
 }

缺少退货声明。你应该将回报添加到该行。