File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -42,3 +42,51 @@ use function ArrayHelpers\array_get;
42
42
$result = array_get($array, $key, $default);
43
43
```
44
44
45
+ ### Available helpers
46
+
47
+ #### Array Get
48
+
49
+ This helper allows you to get an item from an array using dot notation.
50
+ If the item is not found, it will return a given default or null.
51
+
52
+ ```
53
+ $data = [
54
+ 'foo' => [
55
+ 'bar' => 'baz',
56
+ ],
57
+ ];
58
+
59
+ Arr::get($data, 'foo');
60
+ // returns: ['bar' => 'baz'];
61
+
62
+ Arr::get($data, 'foo.bar');
63
+ // returns: 'baz';
64
+
65
+ Arr::get($data, 'xyz', 'default');
66
+ // returns: 'default';
67
+ ```
68
+
69
+ Note that ` Arr::get() ` can be replaced with ` array_get() ` if you prefer a functional approach.
70
+
71
+ #### Array Has
72
+
73
+ This helper checks if an item exists in an array using dot notation.
74
+
75
+ ```
76
+ $data = [
77
+ 'foo' => [
78
+ 'bar' => 'baz',
79
+ ],
80
+ ];
81
+
82
+ Arr::has($data, 'foo');
83
+ // returns: true;
84
+
85
+ Arr::has($data, 'foo.bar');
86
+ // returns: true;
87
+
88
+ Arr::has($data, 'xyz');
89
+ // returns: false;
90
+ ```
91
+
92
+ Note that ` Arr::has() ` can be replaced with ` array_has() ` if you prefer a functional approach.
You can’t perform that action at this time.
0 commit comments