Skip to content

Commit dd0bed6

Browse files
committed
Add some documentation
1 parent 2d1c16c commit dd0bed6

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,51 @@ use function ArrayHelpers\array_get;
4242
$result = array_get($array, $key, $default);
4343
```
4444

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.

0 commit comments

Comments
 (0)