Posted By

kosinix on 11/14/12


Tagged

php search array String case insensitive


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

bennettstone


PHP Search String in Array - Case Insensitive


 / Published in: PHP
 

Use it similar to in_array function of PHP.

  1. function in_array_str_i($key, $array){
  2. foreach($array as $element){
  3. if(strcasecmp($key, $element)==0){
  4. return true;
  5. }
  6. }
  7. return false;
  8. }
  9.  
  10. $array = array(
  11. 'string1',
  12. 'string2',
  13. 'StriNg3'
  14. );
  15.  
  16. var_dump(in_array_str_i('string3', $array)); //bool(true). returns true

Report this snippet  

You need to login to post a comment.