ArrayHelper::flatten()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Schemator\Helpers;
6
7
/**
8
 * @internal
9
 */
10
class ArrayHelper
11
{
12
    /**
13
     * Flattens an array.
14
     *
15
     * @param array<mixed> $input array to flatten
16
     *
17
     * @return array<scalar|object> flat array
18
     */
19
    public static function flatten(array $input): array
20
    {
21
        $tmp = [];
22
        foreach ($input as $val) {
23
            if (is_array($val)) {
24
                $tmp = array_merge($tmp, static::flatten($val));
25
            } else {
26
                $tmp[] = $val;
27
            }
28
        }
29
30
        return $tmp;
31
    }
32
}
33