$status 返回 0,但循环就像它的“1”一样。有趣的是我的错误消息是“MySQL DB is in use (status 0)”。
换句话说:我的 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") {
制作==
进行比较。
因此它是假的,因为字符串“0”在 PHP 中被视为“假”值。 文档:http://php.net/boolean#language.types.boolean.casting
关于php - 我的 "if"语句返回 false 即使它是 true,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10433093/