Skip to content

Instantly share code, notes, and snippets.

@jimboobrien
Forked from wpscholar/array-find.php
Created September 20, 2017 23:19
Show Gist options
  • Save jimboobrien/b885b73ee9500d5fe31de6c622ed6150 to your computer and use it in GitHub Desktop.
Save jimboobrien/b885b73ee9500d5fe31de6c622ed6150 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