简体   繁体   English

可变变量在PHP的IF语句中超时

[英]Variable variable Timing Out In An IF Statement In PHP

I am trying to set some dynamic variables to NULL to avoid the "Warning: Undefined variable" warning. 我试图将一些动态变量设置为NULL,以避免出现“警告:未定义的变量”警告。 I am using this piece of code: 我正在使用这段代码:

        $i = 1;
        while($i <= 15){
            if(!isset(${"ss".$i})){
            ${"ss".$i} = null;
            $i = $i + 1;
            }
        }

However, it just times out at 60 seconds Fatal error: Maximum execution time of 60 seconds exceeded in /www/sites/164/edit.php on line 94 但是,它只是在60秒后超时致命错误:在第94行的/www/sites/164/edit.php中超过了60秒的最大执行时间

Any idea why this is happening? 知道为什么会这样吗?

You only increase $i inside the IF statement. 您只能在IF语句中增加$ i。 If the IF is false, it'll be trapped in an infinite loop. 如果IF为假,它将陷入无限循环。

我建议您使用错误控制运算符来抑制警告,而不必每次都运行该循环。

You're getting in infinite loop. 您陷入无限循环。 Change your code to: 将您的代码更改为:

$i = 1;
while($i <= 15) {
   if(!isset(${"ss".$i})){
      ${"ss".$i} = null;
   }
   $i = $i + 1;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM