php - Getting value from function and adding outside of for loop -
i have following:
public function go(){ for($x=0;$x<=31;$x++) { $this->get_answerrules($x); $donetime+=$donetime; } echo $gmdate("i:s", $donetime);; }
and
public function get_answerrules($x){ ... ... ... if($response = $this->request($data)){ $obj = json_decode($response,true); foreach($obj $file) { $time += $file['batch_dura']; } $donetime = $time; return $donetime; }else{} }
how value 31 loop cycles , add them together?
right results coming blank.
you not using results of method call:
public function go(){ for($x=0;$x<=31;$x++) { $this->get_answerrules($x); $donetime+=$donetime; } // below won't work `$gmdate` not in scope of method. echo $gmdate("i:s", $donetime);; }
should like:
public function go() { // initialize variable $donetime = 0; for($x = 0; $x <= 31; $x++) { $donetime += $this->get_answerrules($x); } echo $gmdate("i:s", $donetime); }
Comments
Post a Comment