Herokiller Herokiller - 8 days ago 6
PHP Question

yii2 ActiveRecord multiple where

I want to make multiple where query, with both

<
and
=
operators.

With multiple
=
operators it goes like:

Model::find()->where([
'param1' => 0,
'param2' => 0,
])->all();


With one
<
operator

Model::find()->where([
'<', 'param1', 0
])->all();


How can I apply both these conditions in one
where
array?

Answer
Model::find()->where([
    'and',
    [
        'param1' => 0,
        'param2' => 0,
    ],
    ['<', 'param1', 0]
])->all();
Comments