Last active
December 17, 2020 13:36
-
-
Save Mika-/00c869f1fef0bc7e3f42679323bf7b99 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Find first element from array by callback | |
* | |
* @param array|\Traversable $array | |
* @param callable $callback | |
* @return mixed|null | |
*/ | |
function array_find($array, callable $callback) | |
{ | |
foreach ($array as $key => $value) { | |
$result = $callback($value, $key, $array); | |
if ($result) { | |
return $value; | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment