这有效:
if ( strtolower($make)=="toyota" && ( strpos(strtolower($model), "scion") !== false || strpos(strtolower($model), "scoin") !== false || strtolower($model) == "xa" || strtolower($model) == "xb" || strtolower($model) == "tc" || strtolower($model) == "xd" || strtolower($model) == "iq" || strtolower($model) == "fr-s" || strtolower($model) == "ia" || strtolower($model) == "im" ) ){
//turn make into scion
$make = "scion";
}
这行不通
$db_scion_models = "";
$scion_models_result = mysqli_query($conn,"SELECT DISTINCT vehicle_model_name FROM mod_vehicle_models WHERE mod_vehicle_make_id = '41' "); //41=scion
while ($scion_model_row = mysqli_fetch_assoc($scion_models_result)) {
$db_scion_models .= '|| strtolower($model) == "'.$scion_model_row['vehicle_model_name'].'" ';
}
if (!empty($db_scion_models)) {
$db_scion_models = 'strpos(strtolower($model), "scion") !== false || strpos(strtolower($model), "scoin") !== false '.$db_scion_models;
} else {
$db_scion_models = 'strpos(strtolower($model), "scion") !== false || strpos(strtolower($model), "scoin") !== false';
}
if ( strtolower($make)=="toyota" && ( $db_scion_models ) ){
//turn make into scion
$make = "scion";
}
if 语句有变量来尝试使其动态化。发生以下情况:
这些正确地转换为接穗: 丰田FR-S 丰田iA 丰田IM 丰田tC 这些转化为接穗但不应该: 丰田4runner 丰田阿瓦隆 丰田凯美瑞 丰田花冠 丰田汉兰达 丰田普锐斯
if 语句以静态方式拼写。发生以下情况:
这些正确地转换为接穗: 丰田FR-S 丰田iA 丰田IM 丰田tC 这些不会转化为接穗: 丰田4runner 丰田阿瓦隆 丰田凯美瑞 丰田花冠 丰田汉兰达 丰田普锐斯
我希望动态和静态的工作方式相同。我做错了什么?
字符串中的PHP源码与PHP源码求值结果不一样
比较你的代码的简化版本:
$a = "a";
$b = "b";
$result = '$a === "a"';
$result = $result . '($b === "b")';
echo $result;
给出1.
…使用 PHP 作为 PHP 而不是 PHP 字符串的方法:
$a = "a";
$b = "b";
$result = $a === "a";
$result = $result && ($b === "b");
echo $result;
给出$a === "a"($b === "b")