Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
the-pulli committed Sep 22, 2023
1 parent a62c93b commit 0c5964b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,26 @@ composer require pulli/collection-macros
## Macros

- mapToCollection
- recursiveToArray

### `mapToCollection`

Maps all arrays recursively to a collection.
Maps all arrays/objects recursively to a collection object of collections, which allow nested function calling.

```php
$collection = Collection::mapToCollection([['test' => 1],2,3]);

$collection->get(0)->get('test'); // return 1;
$collection->get(0)->get('test'); // returns 1

// Item has a toArray() public method, then it can be wrapped into a collection like this:
$collection = Collection::mapToCollection([Item(),Item()], true);
```

### `recursiveToArray`

Like `mapToCollection` it maps all arrays/objects recursively to an array.

```php
// Item has a toArray() public method, then it can be wrapped into the collection like this:
$collection = Collection::recursiveToArray(['item1' => Item(), 'item2' => Item()]);
```

0 comments on commit 0c5964b

Please sign in to comment.