note 88281 modified in function.array-key-exists by danbrown
| From: | danbrown@php.net | Date: | Mon, 19 Jan 2009 16:58:44 +0000 |
| Subject: | note 88281 modified in function.array-key-exists by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149463@lists.php.net to get a copy of this message | ||
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.
--was--
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. :)
http://php.net/manual/en/function.array-key-exists.php