src/Bag.php
public function sort($order = SORT_ASC, $flags = SORT_REGULAR, $preserveKeys = false)
    {
        $this->validateSortArgs($order, $flags);

        $items = $this->items;

        if (!$preserveKeys) {
            if ($order === SORT_ASC) {
                sort($items, $flags);
            } elseif ($order === SORT_DESC) {
                rsort($items, $flags);
            }
        } else {
            if ($order === SORT_ASC) {
                asort($items, $flags);
            } elseif ($order === SORT_DESC) {
                arsort($items, $flags);
            }
        }

        return $this->createFrom($items);
    }
public function sort($order = SORT_ASC, $flags = SORT_REGULAR, $preserveKeys = false)
    {
        $this->validateSortArgs($order, $flags);

        $items = $this->items;

        if (!$preserveKeys) {
            if ($order === SORT_ASC) {
                sort($items, $flags);
            } elseif ($order === SORT_DESC) {
                rsort($items, $flags);
            }
        } else {
            if ($order === SORT_ASC) {
                asort($items, $flags);
            } elseif ($order === SORT_DESC) {
                arsort($items, $flags);
            }
        }

        return $this->createFrom($items);
    }
public function sort ( $ order = SORT_ASC , $ flags = SORT_REGULAR , $ preserveKeys = false ) { $ this -> validateSortArgs ( $ order , $ flags ) ; $ items = $ this -> items ; if ( ! $ preserveKeys ) { if ( $ order === SORT_ASC ) { sort ( $ items , $ flags ) ; } elseif ( $ order === SORT_DESC ) { rsort ( $ items , $ flags ) ; } } else { if ( $ order === SORT_ASC ) { asort ( $ items , $ flags ) ; } elseif ( $ order === SORT_DESC ) { arsort ( $ items , $ flags ) ; } } return $ this -> createFrom ( $ items ) ; }
Returns a bag with the values sorted.

Sorting flags:
Constant                        | Description
------------------------------- | ------------------------
`SORT_REGULAR`                  | compare values without changing types
`SORT_NUMERIC`                  | compare values numerically
`SORT_STRING`                   | compare values as strings
`SORT_STRING | SORT_FLAG_CASE`  | compare values as strings ignoring case
`SORT_LOCALE_STRING`            | compare values as strings based on the current locale
`SORT_NATURAL`                  | compare values as strings using "natural ordering"
`SORT_NATURAL | SORT_FLAG_CASE` | compare values as strings using "natural ordering" ignoring case

@param int  $order        `SORT_ASC` or `SORT_DESC`
@param int  $flags        Sorting flags to modify the behavior
@param bool $preserveKeys Whether to preserve keys for maps or to re-index for lists

@return static
Returns a bag with the values sorted .