2016-01-26 33 views
1

如果存在匹配的郵政編碼,我需要檢查數組以匹配數組。我沒有意識到的問題是它是區分大小寫的。在數組中查找郵政編碼忽略大小寫

有沒有辦法讓這種情況下不敏感?的

$outlimit_postal = "V0R1A0,X0E0A0,J0M1V0,P0V1B0,X0A0A0,X0C0E0,P0L1A0,J0M1X0,X0C0A0,X0B2A0,P0V1E0,R0B0A0,P0V1G0,S0J0H0,A0K1N0,V0P1B0,R0C0J0,R0B0B0,X0B0C0,X0A0C0,P0V1J0,X0C0B0,G0G1G0,X0A0E0,X0E1L0,X0C0C0,V0N1M0,P0V1N0,X0E0G0,P0T1L0,X0A0G0,S0J0W0,P0L1H0,T0P1B0,X0E0H0,P0V1W0,T0H1R0,G0G1M0,X0B1J0,R0B0M0,R0B0N0,R0B0P0,X0A0J0,X0A0K0,G0G1N0,V0V1A0,X0E0S0,A0P1G0,X0A0L0,J0M1M0,X0A0H0,X0A1H0,R0B0T0,J0M1H0,J0M1N0,J0M1K0,J0M1A0,P0V1Y0,P0L1S0,G0G1S0,P0V3G0,X0A0N0,V0N2B0,P0V1Z0,V0V1C0,V0T1L0,X0B1K0,X0B0E0,J0M1C0,J0M1G0,V0P1J0,G0G1T0,R0B2E0,P0T1Z0,V0V1H0,R0B0V0,X0E1A0,A0P1J0,V0P1L0,P0V3B0,G0G2C0,A0P1L0,A0P1A0,R0B0Z0,X0E0V0,P0V2G0,V0T1P0,P0T2L0,Y0B1N0,V0V1E0,V0N3S0,R0B1C0,X0A0R0,R0B2G0,X0E1N0,P0L2H0,P0V2L0,X0A0S0,P0V3E0,R0B0Z0,G0G2Y0,A0P1N0,R0B1G0,J0M1P0,X0A0B0,J0M1J0,X0E1R0,X0C0G0,R0B1H0,V0P1P0,X0C0H0,X0A0V0,A0P1P0,P0V2P0,X0E0Z0,J0M1S0,P0V1V0,X0A0W0,R0B1K0,V0P1S0,R0B1N0,G0G2R0,R0B1J0,R0B2H0,S0J2R0,V0P1V0,V0N3H0,P0T3B0,V0P1W0,R0B2C0,X0B1B0,J0M1T0,G0G2W0,X0E1Z0,V0J3N0,X0E1C0,X0E0K0,J0M1Y0,S0J2W0,R0B1Z0,V0J3B0,P0V2Y0,P0T3A0,X0E1W0,X0E1P0,X0C0J0,A0K5V0,S0J3C0,P0V2Z0,R0B2B0"; 
     $allowed_postal_codes = explode(',', $outlimit_postal); 
     $postal_no_space = str_replace(' ', '', $order->delivery['postcode']); 


     if ($this->enabled == true) { 
      if (in_array($postal_no_space, $allowed_postal_codes)) { 
       $this->enabled = false; 
      } 
+2

爲什麼即使所有的陣列東西煩惱呢? pcos足夠一致......'if(stripos($ outlimit_postal,$ postal_no_spacce)!== false))' –

+2

'if(in_array(strtoupper($ postal_no_space),$ allowed_postal_codes)){'只是大小寫用戶輸入匹配數組。 –

+0

嗯好點..我有一種感覺,我做了一個數組最初是因爲某事..雖然我不知道是什麼。 – Sackling

回答

0

如果你想這樣做沒有stripos函數()

  • 代碼中的花括號缺失。
  • $ postal_no_space轉換爲大寫,然後再進行比較。

更正:

$allowed_postal_codes = explode(',', $outlimit_postal); 
$postal_no_space = str_replace(' ', '', $order->delivery['postcode']); 

if ($this->enabled == true) { 
    if (in_array(strtoupper($postal_no_space), $allowed_postal_codes)) { 
     $this->enabled = false; 
    } 
}