-
-
Save jimboobrien/b885b73ee9500d5fe31de6c622ed6150 to your computer and use it in GitHub Desktop.
Case insensitive array_search() with partial matches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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