Passed
Pull Request — master (#51)
by Dominik
02:37
created

array_flatten()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
if (! function_exists('array_map_keys')) {
6
    /**
7
     * @param  array  $input
8
     * @param  callable  $callback
9
     * @return array
10
     */
11
    function array_map_keys($input, $callback)
12
    {
13 1
        $output = [];
14
15 1
        foreach ($input as $key => $value) {
16 1
            $output[] = $callback($key, $value);
17
        }
18
19 1
        return $output;
20
    }
21
}
22
23
if (! function_exists('array_flatten')) {
24
    /**
25
     * @param  array  $array
26
     * @return array
27
     */
28
    function array_flatten($array): array
29
    {
30
        $return = [];
31
32
        array_walk_recursive($array, function ($x) use (&$return) {
33
            $return[] = $x;
34
        });
35
36
        return $return;
37
    }
38
}
39