Skip to content

Commit 554b6a8

Browse files
[12.x] Add Arr::select method documentation (#10216)
* Add Arr::select method documentation * Add PHP opening tag to Arr::select method documentation * fix grammar issue * Update helpers.md --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 6a37e9b commit 554b6a8

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

helpers.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Laravel includes a variety of global "helper" PHP functions. Many of these funct
6767
[Arr::query](#method-array-query)
6868
[Arr::random](#method-array-random)
6969
[Arr::reject](#method-array-reject)
70+
[Arr::select](#method-array-select)
7071
[Arr::set](#method-array-set)
7172
[Arr::shuffle](#method-array-shuffle)
7273
[Arr::sort](#method-array-sort)
@@ -835,8 +836,6 @@ $items = Arr::random($array, 2);
835836
The `Arr::reject` method removes items from an array using the given closure:
836837

837838
```php
838-
<?php
839-
840839
use Illuminate\Support\Arr;
841840

842841
$array = [100, '200', 300, '400', 500];
@@ -848,6 +847,25 @@ $filtered = Arr::reject($array, function (string|int $value, int $key) {
848847
// [0 => 100, 2 => 300, 4 => 500]
849848
```
850849

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+
851869
<a name="method-array-set"></a>
852870
#### `Arr::set()` {.collection-method}
853871

0 commit comments

Comments
 (0)