summaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
authorSimon Rettberg2020-04-20 11:49:17 +0200
committerSimon Rettberg2020-04-20 11:49:17 +0200
commit5eaa4292c6db2c1ee1282c938c899dc5b88db65f (patch)
tree137eaa063302b055ddec03e2c4c3ff5c084f11bf /inc
parent[serversetup-bwlp-ipxe] Fix: Imported PXELINUX entries are invalid (diff)
downloadslx-admin-5eaa4292c6db2c1ee1282c938c899dc5b88db65f.tar.gz
slx-admin-5eaa4292c6db2c1ee1282c938c899dc5b88db65f.tar.xz
slx-admin-5eaa4292c6db2c1ee1282c938c899dc5b88db65f.zip
[statistics] New filter UI
Diffstat (limited to 'inc')
-rw-r--r--inc/arrayutil.inc.php23
1 files changed, 22 insertions, 1 deletions
diff --git a/inc/arrayutil.inc.php b/inc/arrayutil.inc.php
index ec6e2a5f..490b5a4f 100644
--- a/inc/arrayutil.inc.php
+++ b/inc/arrayutil.inc.php
@@ -10,7 +10,7 @@ class ArrayUtil
* @param string $key
* @return array
*/
- public static function flattenByKey($list, $key)
+ public static function flattenByKey(array $list, string $key)
{
$ret = [];
foreach ($list as $item) {
@@ -21,4 +21,25 @@ class ArrayUtil
return $ret;
}
+ /**
+ * Pass an array of arrays you want to merge. The keys of the outer array will become
+ * the inner keys of the resulting array, and vice versa.
+ * @param array $arrays
+ * @return array
+ */
+ public static function mergeByKey(array $arrays)
+ {
+ $empty = array_combine(array_keys($arrays), array_fill(0, count($arrays), false));
+ $out = [];
+ foreach ($arrays as $subkey => $array) {
+ foreach ($array as $key => $item) {
+ if (!isset($out[$key])) {
+ $out[$key] = $empty;
+ }
+ $out[$key][$subkey] = $item;
+ }
+ }
+ return $out;
+ }
+
} \ No newline at end of file