Conditions | 4 |
Paths | 5 |
Total Lines | 18 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
14 | function flatten(array $items, ?string $pathSeparator = null): array |
||
15 | { |
||
16 | $result = []; |
||
17 | $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($items)); |
||
18 | foreach ($iterator as $leafValue) { |
||
19 | $keys = []; |
||
20 | foreach (range(0, $iterator->getDepth()) as $depth) { |
||
21 | $keys[] = $iterator->getSubIterator($depth)->key(); |
||
22 | } |
||
23 | |||
24 | if (! empty($pathSeparator)) { |
||
25 | $result[join($pathSeparator, $keys) ] = $leafValue; |
||
26 | } else { |
||
27 | $result[] = $leafValue; |
||
28 | } |
||
29 | } |
||
30 | |||
31 | return $result; |
||
32 | } |
||
33 |