From d178d05272863bb8d920a993b7d6fc4b1f275dcf Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Tue, 13 Jun 2017 22:19:11 -0400 Subject: Add object function arrayUnique() --- app/class/object.class.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'app') diff --git a/app/class/object.class.php b/app/class/object.class.php index 461f1b1..c1ba85c 100644 --- a/app/class/object.class.php +++ b/app/class/object.class.php @@ -70,6 +70,32 @@ class object extends table return $obj->objtype; } + /* + * Remove duplicate elements from an array of Scrott objects. This + * function compares object GUIDs to check for uniqueness. Array + * keys are preserved. NULL elements are removed. Resulting array + * is returned. + */ + public static function arrayUnique(array $arr) : array + { + $guids = array(); + $ret = array(); + + foreach ($arr as $k => $v) + { + if ($v === NULL) + continue; + + if (in_array($v->guid, $guids)) + continue; + + $guids[] = $v->guid; + $ret[$k] = $v; + } + + return $ret; + } + /* * Get the owner of this object. Either a user object or a group * object will be returned. If this object does not have an owner, -- cgit v1.2.3