You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+136Lines changed: 136 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -16,3 +16,139 @@ To use this library in your project, please install it via composer:
16
16
```
17
17
$ composer require boesing/typed-arrays
18
18
```
19
+
20
+
## Usage
21
+
22
+
The main reason why this library was created was the fact, that *every* array in PHP is a hashmap.
23
+
If you primarily work with APIs, you might have experienced that `json_encode` of an array type sometimes leads to annoying issues.
24
+
25
+
To get rid of `array` being passed through an application, the `OrderedListInterface` and the `MapInterface` became very handy.
26
+
To also provide most if not any of the `array_*` functions to the developers, most of these array functions do have a method within `OrderedListInterface` or `MapInterface`.
27
+
28
+
### Common mistakes
29
+
30
+
Lets take some real-world use cases to better reflect the idea behind this library:
31
+
32
+
```php
33
+
$listOfIntegers = [1, 2, 3, 4];
34
+
35
+
$myObject = new stdClass();
36
+
$myObject->integers = $listOfIntegers;
37
+
38
+
echo json_encode($myObject) . PHP_EOL;
39
+
40
+
// Output of the code above will be: `{"integers":[1,2,3,4]}`
41
+
// Now some refactoring has to be made since the requirement changed. The requirement now is that the integers list
42
+
// must not contain odd values anymore. So `array_filter` to the rescue, right?
0 commit comments