我一直在挠头一段时间试图弄清楚这一点。
我有一个看起来像...的数组
$param = array(
"conditionType" => $_GET['conditionType'] ? strtolower($_GET['conditionType']) : "all",
"minPrice" => $_GET['minPrice'] ? $_GET['minPrice'] : false,
"maxPrice" => $_GET['maxPrice'] ? $_GET['maxPrice'] : false,
);
我需要检查以确保返回的所有书籍 >= 最低价格和 <= 最高价格,但如果这些用户选择不指定最低或最高价格,则 if 语句需要忽略此检查。
if(($param['conditionType'] == "all"
|| ($param['conditionType'] == "new" && strtolower($book['sub_condition']) == "new")
|| ($param['conditionType'] == "used" && strtolower($book['sub_condition']) != "new"))
&& ($param['minPrice'] && $book['price'] >= $param['minPrice'])
&& ($param['maxPrice'] && $book['price'] <= $param['maxPrice'])
&& $book['price'] != "null"
){
$books[] = array(
"link" => $book['link'],
"listing_condition" => $book['sub_condition'],
"listing_price" => $book['price']
);
}
我可以在 if 语句中进行哪些更改以确保发生这种情况?