从函数中获取值并在 for 循环外添加

Getting value from function and adding outside of for loop

我有以下内容:

public function go(){
            for($x=0;$x<=31;$x++) {
                $this->get_answerrules($x);
                $DoneTime+=$DoneTime;
            }
            echo $gmdate("i:s", $DoneTime);;
        }

public function get_answerrules($x){
 ...
 ...
 ... 
        if($response = $this->request($data)){
            $obj = json_decode($response,true); 
                foreach($obj as $file) {
                        $Time += $file['batch_dura'];
                }
                $DoneTime = $Time;
                return $DoneTime;
       }else{}  
}

如何从 31 个 for 循环中获取值并将它们相加?

现在我的结果是空白的。

您没有使用方法调用的结果:

public function go(){
    for($x=0;$x<=31;$x++) {
        $this->get_answerrules($x);
        $DoneTime+=$DoneTime;
    }
    // The below won't work as `$gmdate` is not in the scope of the method.
    echo $gmdate("i:s", $DoneTime);;
}

大概应该是这样的:

public function go() {
    // Initialize the variable
    $DoneTime = 0;
    for($x = 0; $x <= 31; $x++) {
        $DoneTime += $this->get_answerrules($x);
    }
    echo $gmdate("i:s", $DoneTime);
}