yii\db\QueryBuilder::buildAndCondition PHP Method

buildAndCondition() public method

Connects two or more SQL expressions with the AND or OR operator.
public buildAndCondition ( string $operator, array $operands, array &$params ) : string
$operator string the operator to use for connecting the given operands
$operands array the SQL expressions to connect.
$params array the binding parameters to be populated
return string the generated SQL expression
    public function buildAndCondition($operator, $operands, &$params)
    {
        $parts = [];
        foreach ($operands as $operand) {
            if (is_array($operand)) {
                $operand = $this->buildCondition($operand, $params);
            }
            if ($operand instanceof Expression) {
                foreach ($operand->params as $n => $v) {
                    $params[$n] = $v;
                }
                $operand = $operand->expression;
            }
            if ($operand !== '') {
                $parts[] = $operand;
            }
        }
        if (!empty($parts)) {
            return '(' . implode(") {$operator} (", $parts) . ')';
        } else {
            return '';
        }
    }