阅读(3500) (0)

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

2021-07-02 16:48:58 更新

如果给定的键在数组中不存在或给定的键的值被设置为 null ,那么 Arr::add 函数将会把给定的键值对添加到数组中:

use Illuminate\Support\Arr;

$array = Arr::add(['name' => 'Desk'], 'price', 100);

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

$array = Arr::add(['name' => 'Desk', 'price' => null], 'price', 100);

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