diff --git a/helpers.md b/helpers.md index ca74b44d3e8..254f3f17f38 100644 --- a/helpers.md +++ b/helpers.md @@ -40,6 +40,8 @@ Laravel includes a variety of global "helper" PHP functions. Many of these funct [Arr::accessible](#method-array-accessible) [Arr::add](#method-array-add) +[Arr::array](#method-array-array) +[Arr::boolean](#method-array-boolean) [Arr::collapse](#method-array-collapse) [Arr::crossJoin](#method-array-crossjoin) [Arr::divide](#method-array-divide) @@ -48,10 +50,12 @@ Laravel includes a variety of global "helper" PHP functions. Many of these funct [Arr::exists](#method-array-exists) [Arr::first](#method-array-first) [Arr::flatten](#method-array-flatten) +[Arr::float](#method-array-float) [Arr::forget](#method-array-forget) [Arr::get](#method-array-get) [Arr::has](#method-array-has) [Arr::hasAny](#method-array-hasany) +[Arr::integer](#method-array-integer) [Arr::isAssoc](#method-array-isassoc) [Arr::isList](#method-array-islist) [Arr::join](#method-array-join) @@ -76,6 +80,7 @@ Laravel includes a variety of global "helper" PHP functions. Many of these funct [Arr::sort](#method-array-sort) [Arr::sortDesc](#method-array-sort-desc) [Arr::sortRecursive](#method-array-sort-recursive) +[Arr::string](#method-array-string) [Arr::take](#method-array-take) [Arr::toCssClasses](#method-array-to-css-classes) [Arr::toCssStyles](#method-array-to-css-styles) @@ -261,6 +266,45 @@ $array = Arr::add(['name' => 'Desk', 'price' => null], 'price', 100); // ['name' => 'Desk', 'price' => 100] ``` + +#### `Arr::array()` {.collection-method} + +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`: + +``` +use Illuminate\Support\Arr; + +$array = ['name' => 'Joe', 'languages' => ['PHP', 'Ruby']]; + +$value = Arr::array($array, 'languages'); + +// ['PHP', 'Ruby'] + +$value = Arr::array($array, 'name'); + +// throws InvalidArgumentException +``` + + +#### `Arr::boolean()` {.collection-method} + +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`: + +``` +use Illuminate\Support\Arr; + +$array = ['name' => 'Joe', 'available' => true]; + +$value = Arr::boolean($array, 'available'); + +// true + +$value = Arr::boolean($array, 'name'); + +// throws InvalidArgumentException +``` + + #### `Arr::collapse()` {.collection-method} @@ -413,6 +457,25 @@ $flattened = Arr::flatten($array); // ['Joe', 'PHP', 'Ruby'] ``` + +#### `Arr::float()` {.collection-method} + +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`: + +``` +use Illuminate\Support\Arr; + +$array = ['name' => 'Joe', 'balance' => 123.45]; + +$value = Arr::float($array, 'balance'); + +// 123.45 + +$value = Arr::float($array, 'name'); + +// throws InvalidArgumentException +``` + #### `Arr::forget()` {.collection-method} @@ -495,6 +558,25 @@ $contains = Arr::hasAny($array, ['category', 'product.discount']); // false ``` + +#### `Arr::integer()` {.collection-method} + +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`: + +``` +use Illuminate\Support\Arr; + +$array = ['name' => 'Joe', 'age' => 42]; + +$value = Arr::integer($array, 'age'); + +// 42 + +$value = Arr::integer($array, 'name'); + +// throws InvalidArgumentException +``` + #### `Arr::isAssoc()` {.collection-method} @@ -1048,6 +1130,25 @@ If you would like the results sorted in descending order, you may use the `Arr:: $sorted = Arr::sortRecursiveDesc($array); ``` + +#### `Arr::string()` {.collection-method} + +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`: + +``` +use Illuminate\Support\Arr; + +$array = ['name' => 'Joe', 'languages' => ['PHP', 'Ruby']]; + +$value = Arr::string($array, 'name'); + +// Joe + +$value = Arr::string($array, 'languages'); + +// throws InvalidArgumentException +``` + #### `Arr::take()` {.collection-method}