这是var_dump:
object(stdClass)#27 (8) {
["SETTING_ID"]=> string(2) "25"
["SETTING_SOURCE"]=> string(2) "XV"
["SETTING_FLEET"]=> string(3) "313"
["SETTING_EXAM"]=> string(1) "A"
["SETTING_HIDE"]=> string(1) "0"
["SETTING_THRESHOLD"]=> string(1) "0"
["SETTING_COUNT"]=> string(8) "POSITIVE"
["SETTING_USAGE"]=> string(7) "MILEAGE"
}
我正在测试的变量是SETTING_HIDE。这是使用Code igniter框架从MySQL中提取的。我不知道在工作了相当长的一天之后是否只是我的厚度或者是什么,但无论变量保持什么值,任何if语句都会返回true,即使在将类型转换为布尔值或直接字符串时也是如此比较,即。 ==“0”或==“1”。
任何一双新鲜眼睛的人都会让我感到愚蠢!?! :)
只是为了澄清:
尝试了以下内容:
if($examSetting->SETTING_HIDE == "1") { $showOnABC = "checked=\"checked\""; }
if((bool)$examSetting->SETTING_HIDE) { $showOnABC = "checked=\"checked\""; }
if($examSetting->SETTING_COUNT == "POSITIVE") further on in my code works perfectly.
答案 0 :(得分:0)
if($examSetting->SETTING_HIDE !== "0") { $showOnABC = "checked=\"checked\""; }
可能适合你
答案 1 :(得分:0)
请参阅:http://www.laprbass.com/RAY_temp_kaigoh.php这让我得出结论,这里还有其他的东西,也许是另一段代码?
<?php // RAY_temp_kaigoh.php
error_reporting(E_ALL);
echo '<pre>';
$thing = new StdClass;
$thing->SETTING_ID = "25";
$thing->SETTING_SOURCE = "XV";
$thing->SETTING_FLEET = "313";
$thing->SETTING_EXAM = "A";
$thing->SETTING_HIDE = "0";
$thing->SETTING_THRESHOLD = "0";
$thing->SETTING_COUNT = "POSITIVE";
$thing->SETTING_USAGE = "MILEAGE";
var_dump($thing);
if ( $thing->SETTING_HIDE) echo "TRUTHY";
if (!$thing->SETTING_HIDE) echo "FALSY";
答案 2 :(得分:0)
我认为这只是那些令人讨厌的烦恼之一,但是,
if($examSetting->SETTING_HIDE == "1") {
$showOnABC = "checked=\"checked\"";
} else {
$showOnABC = "";
}
现在完全符合预期。
无论如何,谢谢你。