阅读(3729) (9)

Laravel 8 reverse() {#collection-method}

2021-07-01 15:42:05 更新

reverse 方法用来倒转集合项的顺序,并保留原始的键:

$collection = collect(['a', 'b', 'c', 'd', 'e']);

$reversed = $collection->reverse();

$reversed->all();

/*
    [
        4 => 'e',
        3 => 'd',
        2 => 'c',
        1 => 'b',
        0 => 'a',
    ]
*/