From 5eb8df7432a708284862e4b126e418265d36b4ab Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 2 May 2022 18:49:09 +0200 Subject: [inc/Util] Add types, move error printing functions to their own class --- inc/arrayutil.inc.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'inc/arrayutil.inc.php') diff --git a/inc/arrayutil.inc.php b/inc/arrayutil.inc.php index 3beceb41..d82cdbeb 100644 --- a/inc/arrayutil.inc.php +++ b/inc/arrayutil.inc.php @@ -48,4 +48,22 @@ class ArrayUtil array_multisort($sorter, $sortFlags, $array); } + /** + * Check whether $array contains all keys given in $keyList + * + * @param array $array An array + * @param array $keyList A list of strings which must all be valid keys in $array + * @return boolean + */ + public static function hasAllKeys(array $array, array $keyList): bool + { + if (!is_array($array)) + return false; + foreach ($keyList as $key) { + if (!isset($array[$key])) + return false; + } + return true; + } + } \ No newline at end of file -- cgit v1.2.3-55-g7522