php - How can I get in_array() case-insensitive? -
using code check if value exists in array array may contain values in uppercase. lookup value in lowercase. cannot control array data dynamically generated database need solution ignore case (uppercase/lowercase).
if lookup value exists in array match regardless of case sensitivity.
if (in_array('lookupvalue', $array)) { // }
output of var_dump($url);
:
string(17) "www.paypal.com.au"
output of 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" }
well if can make sure, search word in lowercase, put array in lower case looping through values array_map()
, putting them in lowercase strtolower()
, e.g.
if (in_array('lookupvalue', array_map("strtolower", $array))) { // }
Comments
Post a Comment