blob: ed77c6d8b956b2a644c59cf92e21ea9e1d4821aa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
<?php
declare(strict_types=1);
namespace mystic\forum\utils;
final class ArrayUtils {
use StaticClass;
public static function repeat(mixed $value, int $count): array {
$arr = [];
for ($i = 0; $i < $count; ++$i)
$arr []= $value;
return $arr;
}
public static function fill(\Closure $factory, int $count): array {
$arr = [];
for ($i = 0; $i < $count; ++$i)
$arr []= $factory($i, $count);
return $arr;
}
public static function assocFromPairs(array $pairs): array {
return array_combine(array_column($pairs, 0), array_column($pairs, 1));
}
public static function asPairs(array $arr): array {
$out = [];
foreach ($arr as $k => $v)
$out []= [$k, $v];
return $out;
}
}
|