Test share

3 years ago

DaftMonk

Code

/**
 * Welcome to Tinkerwell!
 *
 * You can tinker using the built-in
 * Laravel 7 application and use all the
 * nice Laravel features right away.
 *
 * Try modifying this file - the changes will
 * be automatically evaluated as you type.
 */

$movies = [
    [
        'name' => 'Back to the Future',
        'released_in' => 1985,
    ],
    [
        'name' => 'Ghostbusters',
        'released_in' => 1984,
    ]
];

collect($movies)
    ->sortBy(function ($movie) {
        return Arr::get($movie, 'released_in');
    })
    ->values()
    ->toArray();

Output

=> [
     [
       "name" => "Ghostbusters",
       "released_in" => 1984,
     ],
     [
       "name" => "Back to the Future",
       "released_in" => 1985,
     ],
   ]
HELO: Local email testing for your desktop!