Created
August 19, 2014 14:11
-
-
Save serebro/b5b1ddda1e180fff6c78 to your computer and use it in GitHub Desktop.
array_find
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
/** | |
* @return mixed or false | |
*/ | |
function array_find($array, $fn) { | |
$next = current($array); | |
while ($next) { | |
$key = key($array); | |
if (call_user_func_array($fn, [$next, $key])) { | |
return $next; | |
} | |
$next = next($array); | |
} | |
return false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment