Skip to content

Commit

Permalink
Optimize Arr::first when array is large (#15213)
Browse files Browse the repository at this point in the history
  • Loading branch information
bepsvpt authored and taylorotwell committed Sep 1, 2016
1 parent 262145d commit 647b3ae
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Illuminate/Support/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,13 @@ public static function exists($array, $key)
public static function first($array, callable $callback = null, $default = null)
{
if (is_null($callback)) {
return empty($array) ? value($default) : reset($array);
if (empty($array)) {
return value($default);
}

foreach ($array as $item) {
return $item;
}
}

foreach ($array as $key => $value) {
Expand Down

0 comments on commit 647b3ae

Please sign in to comment.