Skip to content

Commit 7e4adca

Browse files
committed
arr sole
1 parent 02192ad commit 7e4adca

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

helpers.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Laravel includes a variety of global "helper" PHP functions. Many of these funct
7171
[Arr::select](#method-array-select)
7272
[Arr::set](#method-array-set)
7373
[Arr::shuffle](#method-array-shuffle)
74+
[Arr::sole](#method-array-sole)
7475
[Arr::sort](#method-array-sort)
7576
[Arr::sortDesc](#method-array-sort-desc)
7677
[Arr::sortRecursive](#method-array-sort-recursive)
@@ -920,6 +921,21 @@ $array = Arr::shuffle([1, 2, 3, 4, 5]);
920921
// [3, 2, 5, 1, 4] - (generated randomly)
921922
```
922923

924+
<a name="method-array-sole"></a>
925+
#### `Arr::sole()` {.collection-method}
926+
927+
The `Arr::sole` method retrieves a single value from an array using the given closure. If more than one value within the array matches the given truth test, an `Illuminate\Support\MultipleItemsFoundException` exception will be thrown. If no values match the truth test, an `Illuminate\Support\ItemNotFoundException` exception will be thrown:
928+
929+
```php
930+
use Illuminate\Support\Arr;
931+
932+
$array = ['Desk', 'Table', 'Chair'];
933+
934+
$value = Arr::sole($array, fn (string $value) => $value === 'Desk');
935+
936+
// 'Desk'
937+
```
938+
923939
<a name="method-array-sort"></a>
924940
#### `Arr::sort()` {.collection-method}
925941

0 commit comments

Comments
 (0)