我对 PHP 不太确定,但我通常认为它就像数学一样,括号是在其他任何事情之前完成的。
我有这个:
if( !strncmp($method_id,'OPTION', 6) && ( ($method_id != 'OPTION_5') || ($method_id != 'OPTION_12') ) )
unset( $available_methods[ $method_id ] );
其中$method_id等于OPTION_1 到 12。
如果选项 5 和 12 可用,则有效地取消设置除这两个之外的所有内容。
问题 为什么上述方法不起作用。
编辑
所以我尝试简化它,但我认为我让它更难理解。
这是一个运输循环。可用的方法是ship:REGULAR_LOCAL, ship:EXPRESS_LOCAL, ship:PLAT_LOCAL, ship:REGULAR_INT, ship:EXPRESS_INT, ship:PLAT_INT, 和FREE_SHIPPING[where LOCALis within shipping country, and INTis international]。
当订单超过 100 美元时,会FREE_SHIPPING自动启动,但我也想根据客户的来源来选择其中一个ship:EXPRESS_LOCAL或出席。ship:EXPRESS_INT
if( !strncmp($method_id,'ship:', 5) && ( ($method_id != 'ship:EXPRESS_LOCAL') || ($method_id != 'ship:EXPRESS_INT') ) )
unset( $available_methods[ $method_id ] );
这应该只返回FREE_SHIPPING, 和 要么ship:EXPRESS_LOCAL 要么 ship:EXPRESS_INT。
环形
if( isset( $available_methods['FREE_SHIPPING'] ) ) {
foreach( $available_methods as $method_id => $method ) {
if( !strncmp( $method_id, 'ship:', 5 ) && ( ($method_id != 'ship:EXPRESS_LOCAL') && ($method_id != 'ship:EXPRESS_INT') ) )
unset( $available_methods[ $method_id ] );
}
}
return $available_methods;