diff options
author | Malf Furious <m@lfurio.us> | 2017-06-13 22:19:11 -0400 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2017-06-19 23:57:39 -0400 |
commit | d178d05272863bb8d920a993b7d6fc4b1f275dcf (patch) | |
tree | 835d40c6d4ab4a5adab4cb97308e2e55464a776b /app/class/object.class.php | |
parent | d840a3d9b464ac424d210aeffc01cea0a774377b (diff) | |
download | scrott-d178d05272863bb8d920a993b7d6fc4b1f275dcf.tar.gz scrott-d178d05272863bb8d920a993b7d6fc4b1f275dcf.zip |
Add object function arrayUnique()
Diffstat (limited to '')
-rw-r--r-- | app/class/object.class.php | 26 |
1 files changed, 26 insertions, 0 deletions
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 @@ -71,6 +71,32 @@ class object extends table } /* + * 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, * NULL will be returned. |