0 follower

Class yii\db\ArrayExpression

Inheritanceyii\db\ArrayExpression
ImplementsArrayAccess, Countable, IteratorAggregate, yii\db\ExpressionInterface
Available since version2.0.14
Source Code https://github.com/yiisoft/yii2/blob/master/framework/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[].

Method Details

__construct() public method

ArrayExpression constructor.

public void __construct ( $value, $type null, $dimension 1 )
$value array|yii\db\QueryInterface|mixed

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|null

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 integer

The number of indices needed to select an element

count() public method (available since version 2.0.14)

Count elements of an object

public integer count ( )
return integer

The custom count as an integer.

The return value is cast to an integer.

getDimension() public method

See also dimensions.

public integer getDimension ( )
return integer

The number of indices needed to select an element

getIterator() public method (available since version 2.0.14.1)

Retrieve an external iterator

public Traversable getIterator ( )
return Traversable

An instance of an object implementing Iterator or Traversable

throws yii\base\InvalidConfigException

when ArrayExpression contains QueryInterface object

getType() public method

See also type.

public null|string getType ( )
getValue() public method

See also value.

public array|mixed|yii\db\QueryInterface getValue ( )
offsetExists() public method (available since version 2.0.14)

Whether a offset exists

public boolean offsetExists ( $offset )
$offset mixed

An offset to check for.

return boolean

True on success or false on failure.

The return value will be casted to boolean if non-boolean was returned.

offsetGet() public method (available since version 2.0.14)

Offset to retrieve

public mixed offsetGet ( $offset )
$offset mixed

The offset to retrieve.

return mixed

Can return all value types.

offsetSet() public method (available since version 2.0.14)

Offset to set

public void offsetSet ( $offset, $value )
$offset mixed

The offset to assign the value to.

$value mixed

The value to set.

offsetUnset() public method (available since version 2.0.14)

Offset to unset

public void offsetUnset ( $offset )
$offset mixed

The offset to unset.