You can use array_uintersect() to do this:
<?php $haystack = [ 'apple', 'banana', 'cherry', 'PineApple', 'PEAR', ]; echo ( array_uintersect(['pineapple'], $haystack, 'strcasecmp') ) ? "found\n" : "not found\n";
It calculates the intersection of two arrays using a user-defined function. You feed him two arrays, one holding his needle, and one holding a haystack. As a comparison function, you simply use the php strcasecmp() function.
So, ultimately your state is single-line:
if ([] === array_uintersect([$needle], $haystack, 'strcasecmp'))
Which, since this is php, can be simplified to:
if (array_uintersect([$needle], $haystack, 'strcasecmp'))
Obviously, you can also define a static function for this:
function in_array_icase($needle, &$haystack) { return array_uintersect([$needle], $haystack, 'strcasecmp'); } $jewelry = ['ring', 'bracelet', 'TaTToo', 'chain']; if (in_array_icase('tattoo', $jewelry)) echo "Yea!";
arkascha May 31 '15 at 9:07 a.m. 2015-05-31 09:07
source share