Eloquent\Phony\Difference\DifferenceSequenceMatcher::tupleSort PHP Method

tupleSort() private method

Sort an array by the nested arrays it contains. Helper function for getMatchingBlocks.
private tupleSort ( array $a, array $b ) : integer
$a array First array to compare.
$b array Second array to compare.
return integer -1, 0 or 1, as expected by the usort function.
    private function tupleSort($a, $b)
    {
        $aLength = count($a);
        $bLength = count($b);
        if ($aLength > $bLength) {
            $max = $aLength;
        } else {
            $max = $bLength;
        }
        for ($i = 0; $i < $max; ++$i) {
            if ($a[$i] < $b[$i]) {
                return -1;
            }
            if ($a[$i] > $b[$i]) {
                return 1;
            }
        }
        if ($aLength === $bLength) {
            return 0;
        }
        if ($aLength < $bLength) {
            return -1;
        }
        return 1;
    }