阅读(4400) (0)

Laravel 8 Arr::prepend() {#collection-method}

2021-07-02 16:49:01 更新

Arr::prepend 函数将一个值插入到数组的开始位置:

use Illuminate\Support\Arr;

$array = ['one', 'two', 'three', 'four'];

$array = Arr::prepend($array, 'zero');

// ['zero', 'one', 'two', 'three', 'four'] 

你也可以指定插入值的键:

use Illuminate\Support\Arr;

$array = ['price' => 100];

$array = Arr::prepend($array, 'Desk', 'name');

// ['name' => 'Desk', 'price' => 100]