PHP Search String in Array - Case Insensitive


/ Published in: PHP
Save to your folder(s)

Use it similar to in_array function of PHP.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.