Page 1 of 1

in_array() - case insensitive

Posted: Sat Jun 19, 2010 2:09 pm
by JKM
Hi there,

Code: Select all

$array = array('jpg', 'gif');
$extension = explode('.', $_FILES['file']['name']);
$extension = $extension[count($extension)-1];
$continue = in_array($array, $extension) ? true : false;
Is it possible to make in_array() case insensitive, or is there another function I can use?

Re: in_array() - case insensitive

Posted: Sat Jun 19, 2010 2:34 pm
by requinix
in_array doesn't do string searching. It doesn't know what case-insensitivity means.

If there isn't a built-in function for this (I don't remember one), try your hand at a loop and strcasecmp.

Re: in_array() - case insensitive

Posted: Sat Jun 19, 2010 4:00 pm
by JKM
nevermind:

Code: Select all

$continue = in_array(strtolower($array), $extension) ? true : false;