yii\db\Query::andFilterCompare PHP Method

andFilterCompare() public method

It adds an additional WHERE condition for the given field and determines the comparison operator based on the first few characters of the given value. The condition is added in the same way as in [[andFilterWhere]] so [[isEmpty()|empty values]] are ignored. The new condition and the existing one will be joined using the 'AND' operator. The comparison operator is intelligently determined based on the first few characters in the given value. In particular, it recognizes the following operators if they appear as the leading characters in the given value: - <: the column must be less than the given value. - >: the column must be greater than the given value. - <=: the column must be less than or equal to the given value. - >=: the column must be greater than or equal to the given value. - <>: the column must not be the same as the given value. - =: the column must be equal to the given value. - If none of the above operators is detected, the $defaultOperator will be used.
Since: 2.0.8
public andFilterCompare ( string $name, string $value, string $defaultOperator = '=' )
$name string the column name.
$value string the column value optionally prepended with the comparison operator.
$defaultOperator string The operator to use, when no operator is given in `$value`. Defaults to `=`, performing an exact match.
    public function andFilterCompare($name, $value, $defaultOperator = '=')
    {
        if (preg_match('/^(<>|>=|>|<=|<|=)/', $value, $matches)) {
            $operator = $matches[1];
            $value = substr($value, strlen($operator));
        } else {
            $operator = $defaultOperator;
        }
        return $this->andFilterWhere([$operator, $name, $value]);
    }