realty-abstration

1 month ago

realty-dev

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,
    ],
    [
        'name' => '2001: A Space Odyssey',
        'released_in' => 1968,
    ]
];

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

Output

=> [
     [
       "name" => "2001: A Space Odyssey",
       "released_in" => 1968,
     ],
     [
       "name" => "Ghostbusters",
       "released_in" => 1984,
     ],
     [
       "name" => "Back to the Future",
       "released_in" => 1985,
     ],
   ]
New course: Desktop apps with Electron