尝试使用php根据排名设置对象的购买价格
我试图根据排名给一个物品定价。我的问题是,如果对象没有排名,它将进入下一层。以下是我的代码示例:尝试使用php根据排名设置对象的购买价格,php,Php,我试图根据排名给一个物品定价。我的问题是,如果对象没有排名,它将进入下一层。以下是我的代码示例: switch ($amazonResult['SalesRank']) { case ($amazonResult['SalesRank'] < 1 || trim($amazonResult['SalesRank'])===''|| !isset($amazonResult['SalesRank']) || $amazonResult['SalesRank']=== null): $
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;
}
开关($amazonResult['SalesRank'])){
案例($amazonResult['SalesRank']<1 | | | trim($amazonResult['SalesRank'])===''| | |!isset($amazonResult['SalesRank']))|$amazonResult['SalesRank']==null):
$Price=((浮动)$lowstamazonprice)*;
$payPrice=round($Price,0);//将价格向上或向下四舍五入到最接近的值$
打破
案例($amazonResult['SalesRank']>0&&$amazonResult['SalesRank']]尝试以下方法:
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;
}
if(!isset($amazonResult['SalesRank'])|为空(trim($amazonResult['SalesRank'])){
//如果变量为空,则为case。
}else if($amazonResult['SalesRank']<1){
//一些“有效”值
$Price=((浮动)$lowstamazonprice)*;
$payPrice=round($Price,0);//将价格向上或向下四舍五入到最接近的值$
打破
}否则如果($amazonResult['SalesRank']>0&&$amazonResult['SalesRank'],我认为您需要展开您的问题-$amazonResult['SalesRank']是可能为空的变量吗?如果没有排名,您希望得到什么结果?