Sort A Multi Dimensional Array In Laravel [duplicate]

Solution 1:

here I go... you can use array_multisort PHP function. Link

$new = [
    [
        'id' => 13,
        'name' => 'Tony',
        'jb' => 3,
    ],
    [
        'id' => 15,
        'name' => 'Joe',
        'jb' => 2,
    ],
    [
        'id' => 16,
        'name' => 'Ross',
        'jb' => 1,
    ],
    [
        'id' => 18,
        'name' => 'Monika',
        'jb' => 5,
    ],
    [
        'id' => 20,
        'name' => 'Joye',
        'jb' => 7,
    ],
];
$keys = array_column($new, 'jb');
array_multisort($keys, SORT_ASC, $new);

so as a result you will get link,

Array
(
    [0] => Array
        (
            [id] => 16
            [name] => Ross
            [jb] => 1
        )

    [1] => Array
        (
            [id] => 15
            [name] => Joe
            [jb] => 2
        )

    [2] => Array
        (
            [id] => 13
            [name] => Tony
            [jb] => 3
        )

    [3] => Array
        (
            [id] => 18
            [name] => Monika
            [jb] => 5
        )

    [4] => Array
        (
            [id] => 20
            [name] => Joye
            [jb] => 7
        )

)