Issues (172)

src/functions/iterable_separate.php (1 issue)

Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Improved;
6
7
/**
8
 * Get both keys and values of iterable in separate arrays.
9
 *
10
 * @param iterable $iterable
11
 * @return array[]  ['keys' => array, 'values' => array]
12
 */
13
function iterable_separate(iterable $iterable): array
0 ignored issues
show
Function Improved\iterable_separate() has parameter $iterable with no value type specified in iterable type iterable.
Loading history...
14
{
15 7
    if (is_array($iterable)) {
16 1
        return ['keys' => array_keys($iterable), 'values' => array_values($iterable)];
17
    }
18
19 6
    $keys = [];
20 6
    $values = [];
21
22 6
    foreach ($iterable as $key => $value) {
23 5
        $keys[] = $key;
24 5
        $values[] = $value;
25
    }
26
27 6
    return compact('keys', 'values');
28
}
29