我将此代码与 php 一起使用:
while (0 != $date1 || $this->counter < 5 ) {
// if ($this->true_cahce_failure ) {
$this->url= $this->adjust_url_with_www_add($this->url);
// $this->counter=2;
// }
$this->cache_debug("Date".$date1." ".$this->url,"Recursion ".$this->counter);
$date1 = $this->get_date();
$this->counter++;
}
$this->cache_debug("Date: ".$date1." ".$this->url,"Loop Done ");
基本上循环应该继续,直到 $date
是 not 0
或者 counter
不大于 5
。有时 date1
有 0
但有时没有。如果没有,它应该在 while 评估中返回,并停止迭代。但它并没有这样做,而是继续迭代。
它只在计数器达到 5 时停止。这是为什么?
最佳答案
我认为您想在您的条件中使用 &&
而不是 ||
。
按照您编写的方式,如果其中一个条件为真,它将继续运行,因此只有当它们都为假时,它才会停止。
编辑:仔细阅读您的问题后,我认为您需要使用
while (0 == $date1 && $this->counter < 5 ) {
关于php - 令人费解的 php 递归,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13344602/