note 88281 deleted from function.array-key-exists by crell
| From: | crell@php.net | Date: | Wed, 29 Jun 2022 20:43:20 +0000 |
| Subject: | note 88281 deleted from function.array-key-exists by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218765@lists.php.net to get a copy of this message | ||
Note Submitter: John
----
Here is a little function for case sensitivity to elaborate on what was said by MarkL from ##php
(Freenode) and mmanning at mdanderson dot org from this page:
<?php
// Case sensitive version of array_key_exists() using preg_match()
function array_ikey_exists($key,$arr)
{
if(preg_match("/".$key."/i", join(",", array_keys($arr))))
return true;
else
return false;
}
?>
Not that anyone else couldn't have written this, but a concept like this strengthens
reusability. :)
Also, I've been running into issues with escaping for Regex, so I decided to give something
like this a shot:
<?php
function array_ikey_exists($key,$arr)
{
$e = 0; //$key = addslashes($key);
if(is_array($arr) && $arr !==array())
{
foreach($arr as $k => $v)
{
if(strtolower($k) == strtolower($key))
$e++;
}
if($e>0)
return true;
else
return false;
}
else
return false;
}
?>
You could addslashes() to escape; it's just another approach.