Skip to content

Commit a971256

Browse files
authored
Merge pull request #22 from dmeybohm/better-doc
Improve doc.
2 parents c280e54 + 49d02fa commit a971256

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,35 @@ composer require best/dot-notation
1414

1515
This package has a single class with static methods, `\Best\DotNotation`.
1616

17-
These methods all take an array as their first argument, and most then a "key path" as their
17+
There are two main groups of methods: those that operate recursively
18+
across an entire array, and those that get/set values from such arrays.
19+
20+
### Recursive methods
21+
22+
For the recursive methods, you can use `expand` and `compact` methods to convert
23+
the dots from the expanded form and the compact form, and these operations are
24+
inverses of each other:
25+
26+
```php
27+
use Best\DotNotation;
28+
29+
$array = DotNotation::compact(array(
30+
'my' => array(
31+
'dotted' ==> array(
32+
'key' => 'value'
33+
)
34+
)
35+
));
36+
// returns the dotted array:
37+
array('my.dotted.key' => 'value');
38+
39+
// convert back to the other form:
40+
$original = DotNotation::expand(['my.dotted.key' => 'value']);
41+
```
42+
43+
### Get/set values
44+
45+
For the other methods, pass an array as their first argument, and most then a "key path" as their
1846
second argument, that determines which keys on the array to operate on.
1947

2048
The key path can include dots to indicate subkeys of arrays to access.

0 commit comments

Comments
 (0)