system/classes/Collection.php
public function sort($metric = false, $preserveKeys = true, $descending = false, $options = SORT_REGULAR)
    {
        if ($this->contentModified) {
            $this->generateContent();
        }

        $results = [];
        $values = [];
        foreach ($this->content as $key => $item) {
            $value = $this->getValue($item, $metric);
            $values[$key] = $value;
        }
        
        $descending ? arsort($values, $options) : asort($values, $options);
        
        if ($preserveKeys) {
            foreach (array_keys($values) as $key) {
                $results[$key] = $this->content[$key];
            }
        } else {
            foreach (array_keys($values) as $key) {
                $results[] = $this->content[$key];
            }
        }
        
        return new self($results);
    }
public function sort($metric = false, $preserveKeys = true, $descending = false, $options = SORT_REGULAR)
    {
        if ($this->contentModified) {
            $this->generateContent();
        }

        $results = [];
        $values = [];
        foreach ($this->content as $key => $item) {
            $value = $this->getValue($item, $metric);
            $values[$key] = $value;
        }
        
        $descending ? arsort($values, $options) : asort($values, $options);
        
        if ($preserveKeys) {
            foreach (array_keys($values) as $key) {
                $results[$key] = $this->content[$key];
            }
        } else {
            foreach (array_keys($values) as $key) {
                $results[] = $this->content[$key];
            }
        }
        
        return new self($results);
    }
Sorts the contents of this Container.

@param key The key on which to sort.
@param dir The sort direction.
@return A reference to this Container.