From 1ffcae2b6119b0cfbf7037fc1513ee127b007a84 Mon Sep 17 00:00:00 2001 From: BePsvPT Date: Fri, 2 Sep 2016 02:30:32 +0800 Subject: [PATCH] Optimize Arr::first when array is large --- src/Illuminate/Support/Arr.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Support/Arr.php b/src/Illuminate/Support/Arr.php index bb0d1a9fe280..f72ebce1d5b9 100755 --- a/src/Illuminate/Support/Arr.php +++ b/src/Illuminate/Support/Arr.php @@ -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) {