PHP语法错误,无法理解有什么问题

时间:2013-09-08 19:50:02

标签: php syntax

使用下面的语法我得到这行代码的错误。但是,如果我将代码行从elseif语句更改为if语句,则不会出现错误。有什么问题?

错误行:elseif($weight <= 5000)

我的所有PHP代码:

if ($delivery == 'one') {
if ($weight <= 1000) 
{
            if (royal_s) {
                $first    = 'Royal Mail Small Parcels';
                $first_p  = '3.00';
                $second   = 'Parcelforce 24';
                $second_p = '15.96';
            } elseif (royal_m) {
                $first    = 'Royal Mail Medium Parcels';
                $first_p  = '5.65';
                $second   = 'Parcelforce 24';
                $second_p = '15.96';
            } elseif (parcelforce) {
                $first    = 'Parcelforce 24';   
                $first_p  = '15.96';
            } else {
                sorry;
            }
} 
elseif ($weight  <= 2000) 
{
            if (royal_s){
                $first    = 'Royal Mail Small Parcels';
                $first_p  = '6.85';
                $second   = 'Parcelforce 24';
                $second_p = '15.96';
            } elseif(royal_m) {
                $first    = 'Royal Mail Medium Parcels';
                $first_p  = '8.90';
                $second   = 'Parcelforce 24';
                $second_p = '15.96';
            }
            elseif(parcelforce){
                $first    = 'Parcelforce 24';   
                $first_p  = '15.96';
            } else {
                sorry;
} 
elseif($weight  <= 5000) 
{
            if (royal_m) {
                $first    = 'Royal Mail Medium Parcels';
                $first_p  = '15.10';
                $second   = 'Parcelforce 24';
                $second_p = '16.92';
            } elseif(parcelforce){
                $first    = 'Parcelforce 24';   
                $first_p  = '15.96';
            } else {
                sorry;
            }
}
}
}

1 个答案:

答案 0 :(得分:1)

您的括号位于错误的位置:

 if ($delivery == 'one') {
    if ($weight <= 1000) 
    {
                if (royal_s) {
                    $first    = 'Royal Mail Small Parcels';
                    $first_p  = '3.00';
                    $second   = 'Parcelforce 24';
                    $second_p = '15.96';
                } elseif (royal_m) {
                    $first    = 'Royal Mail Medium Parcels';
                    $first_p  = '5.65';
                    $second   = 'Parcelforce 24';
                    $second_p = '15.96';
                } elseif (parcelforce) {
                    $first    = 'Parcelforce 24';   
                    $first_p  = '15.96';
                } else {
                    sorry;
                }
    } 
    elseif ($weight  <= 2000) 
    {
                if (royal_s){
                    $first    = 'Royal Mail Small Parcels';
                    $first_p  = '6.85';
                    $second   = 'Parcelforce 24';
                    $second_p = '15.96';
                } elseif(royal_m) {
                    $first    = 'Royal Mail Medium Parcels';
                    $first_p  = '8.90';
                    $second   = 'Parcelforce 24';
                    $second_p = '15.96';
                }
                elseif(parcelforce){
                    $first    = 'Parcelforce 24';   
                    $first_p  = '15.96';
                } else {
                    sorry;
    } 
}
    elseif($weight  <= 5000) 
    {
                if (royal_m) {
                    $first    = 'Royal Mail Medium Parcels';
                    $first_p  = '15.10';
                    $second   = 'Parcelforce 24';
                    $second_p = '16.92';
                } elseif(parcelforce){
                    $first    = 'Parcelforce 24';   
                    $first_p  = '15.96';
                } else {
                    sorry;
                }
    }
    }