tags:

views:

77

answers:

3

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
+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
This is the most efficient one.
orlandu63
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
That's a surprising answer, given that two different answers (not using `strotolower`) have already been posted.
Konrad Rudolph
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