It's a big array, so i won't to strtolower every value.
+7
A:
Use preg_grep
with the case insensitivity flag “i
”:
$result = preg_grep('/pattern/i', $array);
Konrad Rudolph
2009-06-25 09:34:42
+1
A:
Try this using the strcasecmp
function:
$array = array('foo', 'bar', 'baz', 'quux');
$needle = 'FOO';
$hit = false;
foreach ($array as $elem) {
if (is_string($elem) && strcasecmp($needle, $elem) == 0) {
$hit = true;
break;
}
}
var_dump($hit);
Gumbo
2009-06-25 09:35:42
This is the most efficient one.
orlandu63
2009-06-25 11:09:32
A:
As I know there is only the way with strtolower. See also the comment in the PHP doc: http://ch2.php.net/manual/en/function.in-array.php#88554
Edit: As you can see in the comment, there is of course more than one way to solve it. I probably miss spelled what I tried to say ;-). Sorry.
Gregor
2009-06-25 09:36:01
That's a surprising answer, given that two different answers (not using `strotolower`) have already been posted.
Konrad Rudolph
2009-06-25 10:32:35
I was just too slow. And to be honest, there are always a lot ways to solve a problem. And I don't see any reason to use strcasecmp or preg_grep wit the i-Flag... For me each of the answers solve the problem...
Gregor
2009-06-25 11:06:06