Skip to content

Commit

Permalink
Show example of accessing an associative array.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemccaffrey authored Feb 27, 2020
1 parent c59def9 commit b7be528
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,21 @@ $output = maybe($entity)->function1()->function2()->return();

### ->array($key)

Access a value when the current object is an array, which requires specifying the desired index:
Access a value when the current object is an indexed array, which requires specifying the desired index:
```php
$output = maybe($entity)->function1()->array(0)->function2()->return();
```

If you omit this function, Maybe will run the next function called on the first item in the array, so this will return the same result:
If you omit this function, Maybe will pass the next function to the first item in the array, so this will return the same result:

```php
$output = maybe($entity)->function1()->function2()->return();
```

You can associative arrays by passing a named key to the funtion:
```php
$output = maybe($entity)->function1()->array('my_array_key')->return();
```

## Future development

Expand Down

0 comments on commit b7be528

Please sign in to comment.