Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Created February 11, 2014 17:28
Show Gist options
  • Save wpscholar/8939676 to your computer and use it in GitHub Desktop.
Save wpscholar/8939676 to your computer and use it in GitHub Desktop.
Case insensitive array_search() with partial matches
<?php
/**
* Case insensitive array_search() with partial matches.
*
* @param string $needle
* @param array $haystack
* @return bool|int|string
*/
public static function array_find( $needle, array $haystack ) {
$found = false;
foreach ( $haystack as $key => $value ) {
if ( false !== stripos( $needle, $value ) ) {
$found = $key;
break;
}
}
return $found;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment