public function sort()
    {
        $index      = 0;
        $comparator = [$this->sorter, 'sort'];

        // add an index to provide stable sorting
        foreach ($this->items as &$item) {
            $item = [$index++, $item];
        }
        unset($item);

        uasort($this->items, function ($a, $b) use ($comparator) {
            $result = $comparator($a[1], $b[1]);

            // use the index to prevent undefined behaviour when comparator reports items are "equal"
            return $result === 0 ? $a[0] - $b[0] : $result;
        });

        // remove the index
        foreach ($this->items as &$item) {
            $item = $item[1];
        }
        unset($item);
    }
public function sort()
    {
        $index      = 0;
        $comparator = [$this->sorter, 'sort'];

        // add an index to provide stable sorting
        foreach ($this->items as &$item) {
            $item = [$index++, $item];
        }
        unset($item);

        uasort($this->items, function ($a, $b) use ($comparator) {
            $result = $comparator($a[1], $b[1]);

            // use the index to prevent undefined behaviour when comparator reports items are "equal"
            return $result === 0 ? $a[0] - $b[0] : $result;
        });

        // remove the index
        foreach ($this->items as &$item) {
            $item = $item[1];
        }
        unset($item);
    }
public function sort ( ) { $ index = 0 ; $ comparator = [ $ this -> sorter , 'sort' ] ; // add an index to provide stable sorting foreach ( $ this -> items as & $ item ) { $ item = [ $ index ++ , $ item ] ; } unset ( $ item ) ; uasort ( $ this -> items , function ( $ a , $ b ) use ( $ comparator ) { $ result = $ comparator ( $ a [ 1 ] , $ b [ 1 ] ) ; // use the index to prevent undefined behaviour when comparator reports items are "equal" return $ result === 0 ? $ a [ 0 ] - $ b [ 0 ] : $ result ; } ) ; // remove the index foreach ( $ this -> items as & $ item ) { $ item = $ item [ 1 ] ; } unset ( $ item ) ; }
Sorts proxy source items using the StableSort algorithm from Martijn van der Lee

See: https://github.com/vanderlee/PHP-stable-sort-functions
Sorts proxy source items using the StableSort algorithm from Martijn van der Lee