使用下面的语法我得到这行代码的错误。但是,如果我将代码行从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;
}
}
}
}
答案 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;
}
}
}