Skip to content

Commit

Permalink
Add some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrieghe committed Oct 13, 2017
1 parent 2d1c16c commit dd0bed6
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,51 @@ use function ArrayHelpers\array_get;
$result = array_get($array, $key, $default);
```

### Available helpers

#### Array Get

This helper allows you to get an item from an array using dot notation.
If the item is not found, it will return a given default or null.

```
$data = [
'foo' => [
'bar' => 'baz',
],
];
Arr::get($data, 'foo');
// returns: ['bar' => 'baz'];
Arr::get($data, 'foo.bar');
// returns: 'baz';
Arr::get($data, 'xyz', 'default');
// returns: 'default';
```

Note that `Arr::get()` can be replaced with `array_get()` if you prefer a functional approach.

#### Array Has

This helper checks if an item exists in an array using dot notation.

```
$data = [
'foo' => [
'bar' => 'baz',
],
];
Arr::has($data, 'foo');
// returns: true;
Arr::has($data, 'foo.bar');
// returns: true;
Arr::has($data, 'xyz');
// returns: false;
```

Note that `Arr::has()` can be replaced with `array_has()` if you prefer a functional approach.

0 comments on commit dd0bed6

Please sign in to comment.