ArrayExpression
API reference › yii › db › ArrayExpression
Class ArrayExpression represents an array SQL expression.
Expressions of this type can be used in conditions as well:
$query->andWhere(['@>', 'items', new ArrayExpression([1, 2, 3], 'integer')])which, depending on DBMS, will result in a well-prepared condition. For example, in
PostgreSQL it will be compiled to WHERE "items" @> ARRAY[1, 2, 3]::integer[].
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | ArrayExpression constructor. | ArrayExpression |
count() | Count elements of an object | ArrayExpression |
getDimension() | ArrayExpression | |
getIterator() | Retrieve an external iterator | ArrayExpression |
getType() | ArrayExpression | |
getValue() | ArrayExpression | |
offsetExists() | Whether a offset exists | ArrayExpression |
offsetGet() | Offset to retrieve | ArrayExpression |
offsetSet() | Offset to set | ArrayExpression |
offsetUnset() | Offset to unset | ArrayExpression |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(array|yii\db\QueryInterface|mixed $value, string|null $type = null, int $dimension = 1)ArrayExpression constructor.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | array|QueryInterface| | The array content. Either represented as an array of values or a Query that returns these values. A single value will be considered as an array containing one element. |
$type | string| | The type of the array elements. Defaults to null which means the type is not explicitly specified. In case when type is not specified explicitly and DBMS can not guess it from the context, SQL error will be raised. |
$dimension | int | The number of indices needed to select an element |
count()
Section titled “count() ”public function count(): intCount elements of an object
Returns
int: The custom count as an integer. </p> <p> The return value is cast to an integer.
Since
2.0.14
getDimension()
Section titled “getDimension() ”public function getDimension(): intReturns
int: The number of indices needed to select an element
getIterator()
Section titled “getIterator() ”public function getIterator(): TraversableRetrieve an external iterator
Returns
Traversable: An instance of an object implementing <b>Iterator</b> or <b>Traversable</b>
Throws
yii\base\InvalidConfigException: when ArrayExpression contains QueryInterface object
Since
2.0.14.1
getValue()
Section titled “getValue() ”public function getValue(): array|mixed|yii\db\QueryInterfaceReturns
array|mixed|QueryInterface
offsetExists()
Section titled “offsetExists() ”public function offsetExists(int|string $offset): boolWhether a offset exists
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | int| | <p> An offset to check for. </p> |
Returns
bool: True on success or false on failure. </p> <p> The return value will be casted to boolean if non-boolean was returned.
Since
2.0.14
offsetGet()
Section titled “offsetGet() ”public function offsetGet(int|string $offset): mixedOffset to retrieve
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | int| | <p> The offset to retrieve. </p> |
Returns
mixed: Can return all value types.
Since
2.0.14
offsetSet()
Section titled “offsetSet() ”public function offsetSet(int|string $offset, mixed $value): voidOffset to set
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | int| | <p> The offset to assign the value to. </p> |
$value | mixed | <p> The value to set. </p> |
Since
2.0.14
offsetUnset()
Section titled “offsetUnset() ”public function offsetUnset(int|string $offset): voidOffset to unset
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | int| | <p> The offset to unset. </p> |
Since
2.0.14