/** * Remove specific keys from the array * @param array $array * @param array $keys The keys to remove * @param string $removal_action One of the removal action constants. Default is to delete keys but you can also * nullify / clear them instead. * @return array */ public static function removeKeys(array $array, $keys, $removal_action = self::REMOVAL_ACTION_DELETE) { //Reuse existing logic return current(CollectionUtility::removeKeys([$array], $keys, $removal_action)); }
/** * Sort a collection by a nested key - maintain key association * @param array $array The collection * @param string $property The name of the property to sort by. This can be a dot separated string. * @param string $sort_direction The direction to sort in. One of the SORT_DIRECTION_* constants or null to sort * ascending. * @param $sort_flags @see http://php.net/manual/en/function.asort.php * @return array */ public static function asort(array $array, $property, $sort_direction = self::SORT_DIRECTION_ASCENDING, $sort_flags = SORT_REGULAR) { $sort_target = CollectionUtility::pluck($array, $property); if ($sort_direction == self::SORT_DIRECTION_ASCENDING || !isset($sort_direction)) { asort($sort_target, $sort_flags); } elseif ($sort_direction == self::SORT_DIRECTION_DESCENDING) { arsort($sort_target, $sort_flags); } else { throw new \InvalidArgumentException("Sort direction '{$sort_direction}' not valid. Must be one of asc, desc."); } return array_replace($sort_target, $array); }