解析数组的函数总是返回 "True"

Function That Parses Array Is Always Returning "True"

我正在为客户构建一个 Shopify 网站,并且我们正在使用一个应用程序 (Bespoke Shipping),该应用程序允许您编写 PHP 代码来操纵传递到函数中的变量。我有一个使用 foreach 循环的测试,我用它来检查订单是否被运送到 48 U.S 的州。状态。该测试总是返回 "true",而它应该只返回 "true" 当较低的 48 个州缩写的数组与它被传送到的州不匹配时。这是我的代码:

$usr_province = $DATA['destination']['province'];

$is_lower_48 = false;
$lower_48 = array('AL', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'FL', 'GA', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY');

foreach ($lower_48 as $m) {
    if ($usr_province == $m) {
        $is_lower_48 = true;
    }
}

if (($DATA['destination']['country'] == 'US') && ($is_lower_48 == true)) {
    /* apply the rules for lower 48 U.S. shipping */
} elseif (($DATA['destination']['country'] == 'US') && ($is_lower_48 == false))  { /* If the destination country is in the US and NOT in the lower 48 states */
    /* apply the rules for non-contiguous U.S. shipping */
}

使用in_array(in array) 函数检查数组中存在的值

$usr_province = $DATA['destination']['province'];

$is_lower_48 = false;
$lower_48 = array('AL', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'FL', 'GA', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY');

if(in_array($usr_province, $lower_48)) {
    $is_lower_48 = true;
}


if (($DATA['destination']['country'] == 'US') && ($is_lower_48 == true)) {
    /* apply the rules for lower 48 U.S. shipping */
} elseif (($DATA['destination']['country'] == 'US') && ($is_lower_48 == false))  { /* If the destination country is in the US and NOT in the lower 48 states */
    /* apply the rules for non-contiguous U.S. shipping */
}