使用以下代码来检查值是否存在于数组中,但有时数组中可能包含大写字母的值。我的查找值始终为小写。由于数组数据是从数据库动态生成的,因此我无法控制它,因此需要一种忽略大小写(大写/小写)的解决方案。
如果查找值存在于数组中,我希望它不区分大小写。
if (in_array('lookupvalue', $array)) {
// do something
}
var_dump($url);
的输出结果:
string(17) "www.paypal.com.au"
var_dump($sans);
的输出结果:
array(52) {
[0]=>
string(13) "WWW.PAYPAL.AT"
[1]=>
string(13) "WWW.PAYPAL.BE"
[2]=>
string(13) "WWW.PAYPAL.CA"
[3]=>
string(13) "WWW.PAYPAL.CH"
[4]=>
string(13) "WWW.PAYPAL.CL"
[5]=>
string(13) "WWW.PAYPAL.CN"
[6]=>
string(16) "WWW.PAYPAL.CO.ID"
[7]=>
string(16) "WWW.PAYPAL.CO.IL"
[8]=>
string(16) "WWW.PAYPAL.CO.IN"
[9]=>
string(19) "WWW.PAYPAL-MENA.COM"
[10]=>
string(16) "WWW.PAYPAL.CO.NZ"
[11]=>
string(16) "WWW.PAYPAL.CO.TH"
[12]=>
string(16) "WWW.PAYPAL.CO.UK"
[13]=>
string(16) "WWW.PAYPAL.CO.ZA"
[14]=>
string(17) "WWW.PAYPAL.COM.AR"
[15]=>
string(17) "WWW.PAYPAL.COM.AU"
[16]=>
string(17) "WWW.PAYPAL.COM.BR"
[17]=>
string(17) "WWW.PAYPAL.COM.HK"
[18]=>
string(17) "WWW.PAYPAL.COM.MX"
[19]=>
string(17) "WWW.PAYPAL.COM.MY"
[20]=>
string(17) "WWW.PAYPAL.COM.SA"
[21]=>
string(17) "WWW.PAYPAL.COM.SG"
[22]=>
string(17) "WWW.PAYPAL.COM.TR"
[23]=>
string(17) "WWW.PAYPAL.COM.TW"
[24]=>
string(17) "WWW.PAYPAL.COM.VE"
[25]=>
string(13) "WWW.PAYPAL.DE"
[26]=>
string(13) "WWW.PAYPAL.DK"
[27]=>
string(13) "WWW.PAYPAL.ES"
[28]=>
string(13) "WWW.PAYPAL.EU"
[29]=>
string(13) "WWW.PAYPAL.FI"
[30]=>
string(13) "WWW.PAYPAL.FR"
[31]=>
string(13) "WWW.PAYPAL.IE"
[32]=>
string(13) "WWW.PAYPAL.IT"
[33]=>
string(13) "WWW.PAYPAL.JP"
[34]=>
string(13) "WWW.PAYPAL.LU"
[35]=>
string(13) "WWW.PAYPAL.NL"
[36]=>
string(13) "WWW.PAYPAL.NO"
[37]=>
string(13) "WWW.PAYPAL.PH"
[38]=>
string(13) "WWW.PAYPAL.PL"
[39]=>
string(13) "WWW.PAYPAL.PT"
[40]=>
string(13) "WWW.PAYPAL.RU"
[41]=>
string(13) "WWW.PAYPAL.SE"
[42]=>
string(13) "WWW.PAYPAL.VN"
[43]=>
string(21) "WWW.THEPAYPALBLOG.COM"
[44]=>
string(25) "WWW.PAYPAL-DEUTSCHLAND.DE"
[45]=>
string(13) "WWW.PAYPAL.CO"
[46]=>
string(17) "WWW.PAYPAL.COM.PE"
[47]=>
string(17) "WWW.PAYPAL.COM.PT"
[48]=>
string(20) "WWW.PAYPAL-FRANCE.FR"
[49]=>
string(20) "WWW.PAYPAL-LATAM.COM"
[50]=>
string(23) "WWW.PAYPAL-MARKETING.PL"
[51]=>
string(15) "DEMO.PAYPAL.COM"
}
var_dump($yourSearchValue);
的确切输出,并将您的数组的 print_r() 输出更换为var_dump($yourArray);
的输出。(如果您在浏览器中,请从源代码中获取输出(右键单击->查看源代码)) - Rizier123