/** * Set Difference * * "returns the difference of sets S and T." * * This function can take multiple arrays, Sets, or values * mixed together * * @static * * @link http://en.wikipedia.org/wiki/Set_(abstract_data_type)#Core_set-theoretical_operations [English] * * @param mixed $S,... Data to difference * * @return array Difference array * */ public static function difference() { $cmp = function ($a, $b) { if ($a === $b) { return 0; } else { return -1; } }; // This closures are more compatible with set values $result = null; foreach (func_get_args() as $arg) { if ($arg instanceof TypesResource\SetInterface) { if ($result === null) { $result = $arg->getPlainArray(); } else { $result = array_udiff($result, $arg->getPlainArray(), $cmp); } } else { if (is_array($arg)) { if ($result === null) { $result = $arg; } else { $result = array_udiff($result, $arg, $cmp); } } else { if ($result === null) { $result = array($arg); } else { $result = array_udiff($result, array($arg), $cmp); } } } } // More object compatible than array_unique SORT_REGULAR return StandardResource\ArrayUtilities::returnUnique($result); }
/** * Get A Range Of Indexes * * This gets an array of objects that have priorities between ranges * * NOTE: The utility function must be used because of incompatibility * of array_unique algorithm * * @param Falcraft\Data\Types\Range $r The range to include * * @return array The appropriate array * */ public function indexRange(Range $r) { return StandardResource\ArrayUtilities::returnUnique(array_merge($this->index($r->getMinimum(), self::HIGHER), $this->index($r->getMaximum(), self::LOWER))); }