-1

I'm trying to find a way to search my array for a case-insensitive string and the string does NOT have to be exact match... for example: I want to search for "Chris" and my array has a record of "Christopher" which I want this to be a match.

So far I have tried (case-insensitive):

if (preg_grep( "/".$fullname."/i" , $array2 ))

and

if (in_array($fullname, $array2))

but no luck with either one when searching for "Chris" inside my array which contains "Christopher"

rubberchicken
  • 1,270
  • 2
  • 21
  • 47

1 Answers1

3

See the answer given by Alix Axel

preg_grep does the trick:

$input = preg_quote('bl', '~'); // don't forget to quote input string!
$data = array('orange', 'blue', 'green', 'red', 'pink', 'brown', 'black');

$result = preg_grep('~' . $input . '~', $data);
Community
  • 1
  • 1
Ghostman
  • 6,042
  • 9
  • 34
  • 53