![](/img/trans.png)
[英]An if statement that always returns true even when it should return false
[英]my “if” statement returns false even if its true, why?
$ status返回0,但循环的行为类似于其“ 1”。 有趣的是,我的错误消息是“正在使用MySQL DB(状态0)”。
换句话说:即使它为true,我的if语句也会失败。
错误在哪里?
include 'status_check.php'; //it takes $check from MySQL DB
if($status = "0") { //if status is 0 go on
include 'status_1.php'; //set status to 1
...
include 'status_0.php'; //after finished operation set status back to 0
} else { //if status is 1 say that its 1
echo "MySQL DB is in use (status ". $status .")";
die;
}
您正在分配,而不是进行比较。
if($status = "0") {
将该==
进行比较。
因此它是错误的,因为在PHP中,字符串“ 0”被视为“假”值。 文件: http : //php.net/boolean#language.types.boolean.casting
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.