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

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

        uasort($items, function ($a, $b) {
            $result = strnatcmp($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 natsort(): Collection
    {
        $index = 0;
        $items = $this->items;

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

        uasort($items, function ($a, $b) {
            $result = strnatcmp($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 natsort ( ) : Collection { $ index = 0 ; $ items = $ this -> items ; foreach ( $ items as & $ item ) { $ item = [ $ index ++ , $ item ] ; } uasort ( $ items , function ( $ a , $ b ) { $ result = strnatcmp ( $ 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 using a "natural order" algorithm.

@return static
Sort an array using a natural order algorithm .