I’ve been scratching my head for a while trying to figure this out.
I have an array which look something like…
$param = array(
"conditionType" => $_GET['conditionType'] ? strtolower($_GET['conditionType']) : "all",
"minPrice" => $_GET['minPrice'] ? $_GET['minPrice'] : false,
"maxPrice" => $_GET['maxPrice'] ? $_GET['maxPrice'] : false,
);
I need to check to make sure that all books returned are >= the min price and <= the max price, but if these user chooses not to specify a min or max price than the if statement needs to ignore this check.
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']
);
}
What can I change in the if statement to make sure this happens?
You need to restructure the parts that read like
to instead read like
This follows your stated logic: either a min price should not be set, or it must be less than or equal to the book price.