Skip to content
PHP Ecosystem
Explore

ArrayExpression

API reference › yii › db › ArrayExpression

classyii\db\ArrayExpression
ImplementsExpressionInterface, ArrayAccess, Countable, IteratorAggregate
Since2.0.14
Sourceframework/db/ArrayExpression.php

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[].

MethodDescriptionDefined by
__construct()ArrayExpression constructor.ArrayExpression
count()Count elements of an objectArrayExpression
getDimension()ArrayExpression
getIterator()Retrieve an external iteratorArrayExpression
getType()ArrayExpression
getValue()ArrayExpression
offsetExists()Whether a offset existsArrayExpression
offsetGet()Offset to retrieveArrayExpression
offsetSet()Offset to setArrayExpression
offsetUnset()Offset to unsetArrayExpression
public function __construct(array|yii\db\QueryInterface|mixed $value, string|null $type = null, int $dimension = 1)

ArrayExpression constructor.

Parameters

ParameterTypeDescription
$valuearray|QueryInterface|mixedThe 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.
$typestring|nullThe 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.
$dimensionintThe number of indices needed to select an element
public function count(): int

Count 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

public function getDimension(): int

Returns

int: The number of indices needed to select an element

public function getIterator(): Traversable

Retrieve an external iterator

Returns

Traversable: An instance of an object implementing <b>Iterator</b> or <b>Traversable</b>

Throws

Since

2.0.14.1

public function getType(): string|null

Returns

string|null

public function getValue(): array|mixed|yii\db\QueryInterface

Returns

array|mixed|QueryInterface

public function offsetExists(int|string $offset): bool

Whether a offset exists

Parameters

ParameterTypeDescription
$offsetint|string<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

public function offsetGet(int|string $offset): mixed

Offset to retrieve

Parameters

ParameterTypeDescription
$offsetint|string<p> The offset to retrieve. </p>

Returns

mixed: Can return all value types.

Since

2.0.14

public function offsetSet(int|string $offset, mixed $value): void

Offset to set

Parameters

ParameterTypeDescription
$offsetint|string<p> The offset to assign the value to. </p>
$valuemixed<p> The value to set. </p>

Since

2.0.14

public function offsetUnset(int|string $offset): void

Offset to unset

Parameters

ParameterTypeDescription
$offsetint|string<p> The offset to unset. </p>

Since

2.0.14