Skip to content

Commit

Permalink
Add ArrayHelper::firstResult helper
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-lenz committed Apr 27, 2023
1 parent b94cf8d commit da8ba65
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/helpers/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@
*/
class ArrayHelper extends ArrayHelperBase
{
/**
* @param iterable $array
* @param callable $callback
* @return mixed
*/
static public function firstResult(iterable $array, callable $callback): mixed {
foreach ($array as $index => $value) {
$result = $callback($value, $index);
if (!is_null($result)) {
return $result;
}
}

return null;
}

/**
* @param object|array $array
* @param string|Closure|array $key
Expand Down

0 comments on commit da8ba65

Please sign in to comment.