2012-05-18 4 views
0

순위에 따라 개체 가격을 책정하려고합니다. 내 문제는 개체에 순위가없는 경우 다음 계층으로 이동한다는 것입니다. 다음은 내 코드 샘플입니다.PHP를 사용하여 순위에 따라 개체의 구매 가격을 설정하려고 시도했습니다

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; 
} 

순위가 비어 있거나 null이거나 0 인 경우 순위를 찾는 방법은 무엇입니까?

$ amazonResult [ 'SalesRank']는 비어있을 수 있으며 각각의 경우에 비교해야하는 값입니다. 이 변수는 쿼리에서 가져온되고 항목이

+0

질문을 확장해야한다고 생각합니다. $ amazonResult [ 'SalesRank']는 잠재적으로 비어있는 변수입니까? 순위가 없다면 어떤 결과를 원하니? – Aerik

답변

0

이 시도 책정 할 때마다 실행됩니다 : 당신이 switch에서 변수와 그 COMPAIR 수 있도록

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; 
} 

case 후 값이 일정해야을 .

귀하의 문제는 $amazonResult['SalesRank']과 같지 않을 수있는 귀하의 케이스 구성이 true 또는 false를 반환한다는 것입니다.

관련 문제