@@ -67,6 +67,7 @@ Laravel includes a variety of global "helper" PHP functions. Many of these funct
67
67
[ Arr::query] ( #method-array-query )
68
68
[ Arr::random] ( #method-array-random )
69
69
[ Arr::reject] ( #method-array-reject )
70
+ [ Arr::select] ( #method-array-select )
70
71
[ Arr::set] ( #method-array-set )
71
72
[ Arr::shuffle] ( #method-array-shuffle )
72
73
[ Arr::sort] ( #method-array-sort )
@@ -835,8 +836,6 @@ $items = Arr::random($array, 2);
835
836
The ` Arr::reject ` method removes items from an array using the given closure:
836
837
837
838
``` php
838
- <?php
839
-
840
839
use Illuminate\Support\Arr;
841
840
842
841
$array = [100, '200', 300, '400', 500];
@@ -848,6 +847,25 @@ $filtered = Arr::reject($array, function (string|int $value, int $key) {
848
847
// [0 => 100, 2 => 300, 4 => 500]
849
848
```
850
849
850
+ <a name =" method-array-select " ></a >
851
+ #### ` Arr::select() ` {.collection-method}
852
+
853
+ The ` Arr::select ` method selects an array of values from an array:
854
+
855
+ ``` php
856
+ use Illuminate\Support\Arr;
857
+
858
+ $array = [
859
+ ['id' => 1, 'name' => 'Desk', 'price' => 200],
860
+ ['id' => 2, 'name' => 'Table', 'price' => 150],
861
+ ['id' => 3, 'name' => 'Chair', 'price' => 300],
862
+ ];
863
+
864
+ Arr::select($array, ['name', 'price']);
865
+
866
+ // [['name' => 'Desk', 'price' => 200], ['name' => 'Table', 'price' => 150], ['name' => 'Chair', 'price' => 300]]
867
+ ```
868
+
851
869
<a name =" method-array-set " ></a >
852
870
#### ` Arr::set() ` {.collection-method}
853
871
0 commit comments