-
-
Save natanfelles/3caa3bb840fad19850091fac58e82aa9 to your computer and use it in GitHub Desktop.
array_find() - A case insensitive array_search() with partial matches
This file contains 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 in-sensitive array_search() with partial matches | |
* | |
* @param string $needle The string to search for. | |
* @param array $haystack The array to search in. | |
* | |
* @author Bran van der Meer <[email protected]> | |
* @since 29-01-2010 | |
*/ | |
function array_find($needle, array $haystack) | |
{ | |
foreach ($haystack as $key => $value) { | |
if (false !== stripos($value, $needle)) { | |
return $key; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment