You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[12.x] Typed getters for Arr helper (docs) (#10354)
* add docs for typed Arr getters
* add disambiguation to new HTML anchors (avoid potential future confusion)
* add default value examples
* formatting
---------
Co-authored-by: Taylor Otwell <taylor@laravel.com>
The `Arr::array` method retrieves a value from a deeply nested array using "dot" notation (just as [Arr::get()](#method-array-get) does), but throws an `InvalidArgumentException` if the requested value is not an `array`:
The `Arr::boolean` method retrieves a value from a deeply nested array using "dot" notation (just as [Arr::get()](#method-array-get) does), but throws an `InvalidArgumentException` if the requested value is not a `boolean`:
The `Arr::float` method retrieves a value from a deeply nested array using "dot" notation (just as [Arr::get()](#method-array-get) does), but throws an `InvalidArgumentException` if the requested value is not a `float<
8000
span class="pl-s">`:
The `Arr::integer` method retrieves a value from a deeply nested array using "dot" notation (just as [Arr::get()](#method-array-get) does), but throws an `InvalidArgumentException` if the requested value is not an `int`:
565
+
566
+
```
567
+
use Illuminate\Support\Arr;
568
+
569
+
$array = ['name' => 'Joe', 'age' => 42];
570
+
571
+
$value = Arr::integer($array, 'age');
572
+
573
+
// 42
574
+
575
+
$value = Arr::integer($array, 'name');
576
+
577
+
// throws InvalidArgumentException
578
+
```
579
+
498
580
<aname="method-array-isassoc"></a>
499
581
#### `Arr::isAssoc()` {.collection-method}
500
582
@@ -1048,6 +1130,25 @@ If you would like the results sorted in descending order, you may use the `Arr::
1048
1130
$sorted = Arr::sortRecursiveDesc($array);
1049
1131
```
1050
1132
1133
+
<aname="method-array-string"></a>
1134
+
#### `Arr::string()` {.collection-method}
1135
+
1136
+
The `Arr::string` method retrieves a value from a deeply nested array using "dot" notation (just as [Arr::get()](#method-array-get) does), but throws an `InvalidArgumentException` if the requested value is not a `string`:
0 commit comments