diff options
Diffstat (limited to 'inc/arrayutil.inc.php')
-rw-r--r-- | inc/arrayutil.inc.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/inc/arrayutil.inc.php b/inc/arrayutil.inc.php new file mode 100644 index 00000000..ec6e2a5f --- /dev/null +++ b/inc/arrayutil.inc.php @@ -0,0 +1,24 @@ +<?php + +class ArrayUtil +{ + + /** + * Take an array of arrays, take given key from each sub-array and return + * new array with just those corresponding values. + * @param array $list + * @param string $key + * @return array + */ + public static function flattenByKey($list, $key) + { + $ret = []; + foreach ($list as $item) { + if (array_key_exists($key, $item)) { + $ret[] = $item[$key]; + } + } + return $ret; + } + +}
\ No newline at end of file |