public function sort(\Closure $p)
    {
        $elements = $this->toArray();

        if (!uasort($elements, $p)) {
            throw new \InvalidArgumentException('Sort failed.');
        }

        return new static(array_values($elements));
    }
public function sort(\Closure $p)
    {
        $elements = $this->toArray();

        if (!uasort($elements, $p)) {
            throw new \InvalidArgumentException('Sort failed.');
        }

        return new static(array_values($elements));
    }
public function sort ( \ Closure $ p ) { $ elements = $ this -> toArray ( ) ; if ( ! uasort ( $ elements , $ p ) ) { throw new \ InvalidArgumentException ( 'Sort failed.' ) ; } return new static ( array_values ( $ elements ) ) ; }
Sort collection with given closure.

@param \Closure $p

@return EntityCollection
Sort collection with given closure .