summaryrefslogtreecommitdiff
path: root/src/application/mystic/forum/utils/ArrayUtils.php
diff options
context:
space:
mode:
authorJonas Kohl2024-09-08 17:53:55 +0200
committerJonas Kohl2024-09-08 17:53:55 +0200
commit415a0a96a76afbe7f1ad2f51862641793caf1b6c (patch)
tree1168316bff6a2ec04ee27db5ada5431ba6631ce4 /src/application/mystic/forum/utils/ArrayUtils.php
Initial commit
Diffstat (limited to 'src/application/mystic/forum/utils/ArrayUtils.php')
-rw-r--r--src/application/mystic/forum/utils/ArrayUtils.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/application/mystic/forum/utils/ArrayUtils.php b/src/application/mystic/forum/utils/ArrayUtils.php
new file mode 100644
index 0000000..ed77c6d
--- /dev/null
+++ b/src/application/mystic/forum/utils/ArrayUtils.php
@@ -0,0 +1,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;
+ }
+}