阅读(1949) (10)

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

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

Arr::pull 函数从数组中返回指定键的值并删除此键值对:

use IlluminateSupportArr;

$array = ['name' => 'Desk', 'price' => 100];

$name = Arr::pull($array, 'name');

// $name: Desk

// $array: ['price' => 100] 

默认值可以作为第三个参数传递给该方法,如果键不存在,则返回该值:

use IlluminateSupportArr;

$value = Arr::pull($array, $key, $default);