无法在php中返回函数的bool值

Aar*_*ron 0 php boolean

我试图使用if语句来使用bool值,但它不起作用.顶部是我正在使用的函数,底部是if语句.当我将if语句更改为false时,我得到结果,但我需要true和false bools.有小费吗

      public function find($key)   {  
    $this->find_helper($key, $this->root);      
}

public function find_helper($key, $current){
    while ($current){
        if($current->data == $key){
            echo " current";
            return true;
        }
        else if ($key < $current->data){
            $current= $current->leftChild;
            //echo " left ";
            }
        else {
            $current=$current->rightChild;
            //echo " right ";
            }
    }
    return false;
}


      if($BST->find($randomNumber)){//how do I get this to return a true value?
        echo  " same ";
}
Run Code Online (Sandbox Code Playgroud)

Bol*_*ock 7

你从,find_helper()但不是从find().如果没有return(见下文),find_helper()则调用该方法,但无论该方法返回什么,都将被丢弃.因此,您的find()方法最终都不返回任何值(无论如何,PHP转换为null).

public function find($key) {  
    return $this->find_helper($key, $this->root);      
}
Run Code Online (Sandbox Code Playgroud)