yii\validators\CompareValidator::compareValues PHP Method

compareValues() protected method

Compares two values with the specified operator.
protected compareValues ( string $operator, string $type, mixed $value, mixed $compareValue ) : boolean
$operator string the comparison operator
$type string the type of the values being compared
$value mixed the value being compared
$compareValue mixed another value being compared
return boolean whether the comparison using the specified operator is true.
    protected function compareValues($operator, $type, $value, $compareValue)
    {
        if ($type === self::TYPE_NUMBER) {
            $value = (double) $value;
            $compareValue = (double) $compareValue;
        } else {
            $value = (string) $value;
            $compareValue = (string) $compareValue;
        }
        switch ($operator) {
            case '==':
                return $value == $compareValue;
            case '===':
                return $value === $compareValue;
            case '!=':
                return $value != $compareValue;
            case '!==':
                return $value !== $compareValue;
            case '>':
                return $value > $compareValue;
            case '>=':
                return $value >= $compareValue;
            case '<':
                return $value < $compareValue;
            case '<=':
                return $value <= $compareValue;
            default:
                return false;
        }
    }