0

Class yii\db\conditions\InCondition

Inheritanceyii\db\conditions\InCondition
Implementsyii\db\conditions\ConditionInterface
Available since version2.0.14
Source Code https://github.com/yiisoft/yii2/blob/master/framework/db/conditions/InCondition.php

Represents IN condition.

Public Methods

Hide inherited methods

Method Description Defined By
__construct() yii\db\conditions\InCondition
fromArrayDefinition() Creates object by array-definition as described in Query Builder – Operator format guide article. yii\db\conditions\InCondition
getColumn() Returns the column(s) being matched. yii\db\conditions\InCondition
getOperator() Returns the comparison operator. yii\db\conditions\InCondition
getValues() Returns the value(s) to match against. yii\db\conditions\InCondition

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( array|string|yii\db\ExpressionInterface|Traversable $column, string $operator, array|integer|string|yii\db\ExpressionInterface|Traversable $values )
$column array|string|yii\db\ExpressionInterface|Traversable

The column name. If it is an array, a composite IN condition will be generated.

$operator string

The operator to use (e.g. IN or NOT IN).

$values array|integer|string|yii\db\ExpressionInterface|Traversable

An array of values that column value should be among. If it is an empty array the generated expression will be a false value if operator is IN and empty if operator is NOT IN.

                public function __construct(
    private array|string|ExpressionInterface|Traversable $column,
    private string $operator,
    private array|int|string|ExpressionInterface|Traversable $values
) {
}

            
fromArrayDefinition() public static method

Creates object by array-definition as described in Query Builder – Operator format guide article.

public static static fromArrayDefinition ( mixed $operator, mixed $operands )
$operator mixed

Operator in uppercase.

$operands mixed

Array of corresponding operands

throws yii\base\InvalidArgumentException

if wrong number of operands have been given.

                public static function fromArrayDefinition($operator, $operands): static
{
    if (!isset($operands[0], $operands[1])) {
        throw new InvalidArgumentException("Operator '$operator' requires two operands.");
    }
    return new static($operands[0], $operator, $operands[1]);
}

            
getColumn() public method

Returns the column(s) being matched.

Normalizes Traversable input to an array on first access and caches the result for subsequent calls.

public array|string|yii\db\ExpressionInterface getColumn ( )
return array|string|yii\db\ExpressionInterface

Column name, list of column names for composite conditions, or an expression.

                public function getColumn(): array|string|ExpressionInterface
{
    if ($this->column instanceof Traversable && !$this->column instanceof ExpressionInterface) {
        $this->column = iterator_to_array($this->column);
    }
    return $this->column;
}

            
getOperator() public method

Returns the comparison operator.

public string getOperator ( )
return string

Operator (for example, IN or NOT IN).

                public function getOperator(): string
{
    return $this->operator;
}

            
getValues() public method

Returns the value(s) to match against.

Normalizes Traversable input to an array on first access and caches the result for subsequent calls.

public array|integer|string|yii\db\ExpressionInterface getValues ( )
return array|integer|string|yii\db\ExpressionInterface

Value list, scalar, or expression used for the comparison.

                public function getValues(): array|int|string|ExpressionInterface
{
    if ($this->values instanceof Traversable && !$this->values instanceof ExpressionInterface) {
        $this->values = iterator_to_array($this->values);
    }
    return $this->values;
}