public function usort(callable $callback): Collection
    {
        $index = 0;
        $items = $this->items;

        foreach ($items as &$item) {
            $item = [$index++, $item];
        }

        usort($items, function ($a, $b) use ($callback) {
            $result = call_user_func($callback, $a[1], $b[1]);

            return $result === 0 ? $a[0] - $b[0] : $result;
        });

        foreach ($items as &$item) {
            $item = $item[1];
        }

        return new static($items);
    }
public function usort(callable $callback): Collection
    {
        $index = 0;
        $items = $this->items;

        foreach ($items as &$item) {
            $item = [$index++, $item];
        }

        usort($items, function ($a, $b) use ($callback) {
            $result = call_user_func($callback, $a[1], $b[1]);

            return $result === 0 ? $a[0] - $b[0] : $result;
        });

        foreach ($items as &$item) {
            $item = $item[1];
        }

        return new static($items);
    }
public function usort ( callable $ callback ) : Collection { $ index = 0 ; $ items = $ this -> items ; foreach ( $ items as & $ item ) { $ item = [ $ index ++ , $ item ] ; } usort ( $ items , function ( $ a , $ b ) use ( $ callback ) { $ result = call_user_func ( $ callback , $ a [ 1 ] , $ b [ 1 ] ) ; return $ result === 0 ? $ a [ 0 ] - $ b [ 0 ] : $ result ; } ) ; foreach ( $ items as & $ item ) { $ item = $ item [ 1 ] ; } return new static ( $ items ) ; }
Sort an array by values using a user-defined comparison function.

@param callable $callback

@return static
Sort an array by values using a user - defined comparison function .