尝试使用php根据排名设置对象的购买价格

I am trying to price an object based on ranking. My problem is that if the object has no ranking it is going to the next tier. Here is a sample of my code:

switch ($amazonResult['SalesRank']) {
case ($amazonResult['SalesRank'] < 1 || trim($amazonResult['SalesRank'])===''|| !isset($amazonResult['SalesRank']) || $amazonResult['SalesRank']=== null):
    $Price=((float) $lowestAmazonPrice) *<some percent to pay>;
    $payPrice = round($Price, 0);  //to round the price up or down to the nearest $
    break; 
case ($amazonResult['SalesRank'] > 0 && $amazonResult['SalesRank'] <= 15000):
    $Price=((float) $lowestAmazonPrice) * <some percent to pay>;
    $payPrice = round($Price, 0);  //to round the price up or down to the nearest $
    break;
default:
    $Price=((float) $lowestAmazonPrice) * <some percent to pay>;
    $payPrice = round($Price, 0);  //to round the price up or down to the nearest $
    break;
}

How do I get it to find the ranking if the ranking is either empty, null, or 0?

$amazonResult['SalesRank'] could be empty, and is the value that needs to be compared in each case. This variable is pulled from a query and is run every time an item is to be priced

Try this:

if(!isset($amazonResult['SalesRank']) || empty(trim($amazonResult['SalesRank'])) {
    // case if the variable is empty.
} else if($amazonResult['SalesRank'] < 1) {
    // some "valid" value
    $Price=((float) $lowestAmazonPrice) *<some percent to pay>;
    $payPrice = round($Price, 0);  //to round the price up or down to the nearest $
    break;
} else if($amazonResult['SalesRank'] > 0 && $amazonResult['SalesRank'] <= 15000) {
    $Price=((float) $lowestAmazonPrice) * <some percent to pay>;
    $payPrice = round($Price, 0);  //to round the price up or down to the nearest $
    break;
} else {
    $Price=((float) $lowestAmazonPrice) * <some percent to pay>;
    $payPrice = round($Price, 0);  //to round the price up or down to the nearest $
    break;
}

The value after case should be constant so that you can compair that with the variable in switch.

Your problem is that your case construct will return true or false which is may be not equal to $amazonResult['SalesRank'].