|
2 | 2 |
|
3 | 3 | [](https://travis-ci.org/minwork/array) [](https://coveralls.io/github/minwork/array?branch=master) [](https://packagist.org/packages/minwork/array) [](https://packagist.org/packages/minwork/array)
|
4 | 4 |
|
5 |
| -* Pack of advanced array functions best suited for: |
6 |
| - * **Multidimensional** arrays |
| 5 | +## Pack of array convenience methods for handling: |
| 6 | + * **Nested** arrays |
7 | 7 | * Arrays of **objects**
|
8 | 8 | * **Associative** arrays
|
9 |
| -* Easily **access**, **validate**, **manipulate** and **transform** arrays |
10 |
| -* Advanced implementation of well known operations |
11 |
| - * Map |
12 |
| - * Filter |
13 |
| - * Group |
14 |
| - * Sort |
15 |
| - * Check |
16 |
| - * And many more... |
| 9 | + * **Chaining** array transformations |
| 10 | +### Easily **create**, **access**, **validate**, **manipulate** and **transform** arrays |
| 11 | +Advanced implementation of well known operations: |
| 12 | + * [Get](https://minwork.gitbook.io/array/common-methods/get-getnestedelement) |
| 13 | + * [Set](https://minwork.gitbook.io/array/common-methods/set-setnestedelement) |
| 14 | + * [Has](https://minwork.gitbook.io/array/common-methods/has) |
| 15 | + * [Map](https://minwork.gitbook.io/array/manipulating-array/mapping) |
| 16 | + * [Filter](https://minwork.gitbook.io/array/manipulating-array/filtering) |
| 17 | + * [Group](https://minwork.gitbook.io/array/manipulating-array/grouping) |
| 18 | + * [Sort](https://minwork.gitbook.io/array/manipulating-array/sorting) |
| 19 | + * [Check](https://minwork.gitbook.io/array/validating-array/check) |
| 20 | + * [And many more...](https://minwork.gitbook.io/array/) |
17 | 21 |
|
18 | 22 | ## Installation
|
19 | 23 |
|
|
27 | 31 | * No external dependencies
|
28 | 32 | * Large variety of usages
|
29 | 33 |
|
| 34 | +## Example of usage |
| 35 | +```php |
| 36 | +// Set nested array value |
| 37 | +$array = Arr::set([], 'key1.key2.key3', 'my_value'); |
| 38 | + |
| 39 | +// Get nested array value |
| 40 | +Arr::get($array, 'key1.key2') -> ['key3' => 'my_value'] |
| 41 | + |
| 42 | +// Check if array has nested element |
| 43 | +Arr::has($array, 'key1.key2.key3') -> true |
| 44 | + |
| 45 | +// Map array while accessing it's key |
| 46 | +Arr::map($array, function ($key, $value) { |
| 47 | + // Your code here |
| 48 | +}); |
| 49 | + |
| 50 | +// Chain few methods |
| 51 | +Arr::obj(['test' => 1, 'foo' => 'bar']) |
| 52 | + ->set('abc', 123) |
| 53 | + ->set('[]', 'auto_index') |
| 54 | + ->remove('foo') |
| 55 | + ->getArray() |
| 56 | +-> |
| 57 | +[ |
| 58 | + 'test' => 1, |
| 59 | + 'abc' => 123, |
| 60 | + 'auto_index' |
| 61 | +] |
| 62 | + |
| 63 | +// Group objects by the result of calling method 'getSize' on each object |
| 64 | +Arr::groupObjects([$cat, $dog, $fish, ...], 'getSize') -> |
| 65 | +[ |
| 66 | + 'medium' => [$cat, $dog, ...], |
| 67 | + 'small' => [$fish, ...], |
| 68 | + ... |
| 69 | +] |
| 70 | +``` |
| 71 | + |
30 | 72 | ## Documentation
|
31 | 73 |
|
32 | 74 | [https://minwork.gitbook.io/array/](https://minwork.gitbook.io/array/)
|
|
0 commit comments