1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| head($array); last($array);
Arr::collapse([[1,2,3], [4,5,6], [7,8,9]]);
$array = ['name' => 'Desk', 'price' => 100, 'products' => ['desk' => ['price' => 100]]]; Arr::except($array, ['price']);
Arr::forget($array 'products.desk');
$array = ['products' => ['desk' => ['price' => 100]]]; Arr::get($array, 'products.desk.price', $defaultValue); data_get($array, 'products.desk.price', $defaultValue); data_get($array, '*.name');
Arr::has($array, ['product.price', 'product.discount']);
Arr::hasAny($array, ['product.name', 'product.discount']);
Arr::prepend($array, 'zero'); Arr::prepend($array, 'Desk', 'name');
Arr::pull($array, 'name', $defaultValue)
Arr::exists($array, 'key');
Arr::first($array, function($value, $key) {return $value >= 2;}, $defaultValue);
$array = ['name' => 'Desk', 'price' => 100, 'orders' => 10]; Arr::only($array, ['name', 'price']);
$array = ['name' => 'Joe', 'languages' => ['PHP', 'Ruby']]; $flattened = Arr::flatten($array);
$array = [ ['developer' => ['id' => 1, 'name' => 'Taylor']], ['developer' => ['id' => 2, 'name' => 'Abigail']], ]; Arr::pluck($array, 'developer.name'); Arr::pluck($array, 'developer.name', 'developer.id');
$array = ['name' => 'Taylor', 'order' => ['column' => 'created_at', 'direction' => 'desc']]; Arr::query($array);
Arr::random($array); Arr::random($array, 2);
Arr::sort($array); array_values(Arr::sort($array, function ($value) { // 如果是字段需要指定排序方式 return $value['name']; }));
Arr::where($array, function ($value, $key) { return is_string($value); });
|