diff --git a/src/Illuminate/Support/Arr.php b/src/Illuminate/Support/Arr.php index 19314186457f..bb0d1a9fe280 100755 --- a/src/Illuminate/Support/Arr.php +++ b/src/Illuminate/Support/Arr.php @@ -452,13 +452,13 @@ public static function set(&$array, $key, $value) } /** - * Sort the array using the given callback. + * Sort the array using the given callback or "dot" notation. * * @param array $array - * @param callable $callback + * @param callable|string $callback * @return array */ - public static function sort($array, callable $callback) + public static function sort($array, $callback) { return Collection::make($array)->sortBy($callback)->all(); } diff --git a/tests/Support/SupportArrTest.php b/tests/Support/SupportArrTest.php index d70512e7e33e..dca20367ab6b 100644 --- a/tests/Support/SupportArrTest.php +++ b/tests/Support/SupportArrTest.php @@ -358,20 +358,25 @@ public function testSet() public function testSort() { - $array = [ + $unsorted = [ ['name' => 'Desk'], ['name' => 'Chair'], ]; - $array = array_values(Arr::sort($array, function ($value) { - return $value['name']; - })); - $expected = [ ['name' => 'Chair'], ['name' => 'Desk'], ]; - $this->assertEquals($expected, $array); + + // sort with closure + $sortedWithClosure = array_values(Arr::sort($unsorted, function ($value) { + return $value['name']; + })); + $this->assertEquals($expected, $sortedWithClosure); + + // sort with dot notation + $sortedWithDotNotation = array_values(Arr::sort($unsorted, 'name')); + $this->assertEquals($expected, $sortedWithDotNotation); } public function testSortRecursive()