我有这个代码的一小部分:
$company = array('relation' => $_SESSION['username']);
$companyresponse = $wcfclient->GetCompany($company);
foreach ($companyresponse->GetCompanyResult as $key => $value){
echo $value[0]; //This is the name of the company
if ($value[1] == TRUE){
echo "Company blocked";
}
elseif($value[1] == FALSE){
echo "Company NOT blocked";
}
echo $value[1]; //This gives me the correct result, in this case: FALSE
Run Code Online (Sandbox Code Playgroud)
$ value [1]的结果为FALSE,但是当它通过我的if语句时它返回:"公司被阻止",所以$ value [1]为TRUE,而它需要为FALSE.
有人能告诉我为什么它没有返回正确的值吗?
我也尝试过:
if ($value[1] == 1){
echo "Company blocked";
}
else{
echo "Company NOT blocked";
}
Run Code Online (Sandbox Code Playgroud)
这给了我值FALSE,但不知何故if语句将其更改为TRUE.
var_dump($value[1])
Run Code Online (Sandbox Code Playgroud)
当我尝试一个被正常阻止的公司时,它给了我正确的结果:
string(4) "True" Company blockedTrue
小智 7
$ value 1的类型是"String"而不是"bool".
转换为布尔值时,以下值被视为FALSE:
Run Code Online (Sandbox Code Playgroud)the boolean FALSE itself the integer 0 (zero) the float 0.0 (zero) the empty string, and the string "0" an array with zero elements an object with zero member variables (PHP 4 only) the special type NULL (including unset variables) SimpleXML objects created from empty tags
每个其他值都被视为TRUE(包括任何资源).
reference:转换为boolean(PHP手册)
所以,"假"==正确!
也许你可以把它们比作字符串:
if(strtoupper($value[1]) == "TRUE"){
//...
}else{
//...
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13991 次 |
最近记录: |