0 關注者

Class yii\db\ArrayExpression

繼承yii\db\ArrayExpression
實作ArrayAccess, Countable, IteratorAggregate, yii\db\ExpressionInterface
自版本起可用2.0.14
原始碼 https://github.com/yiisoft/yii2/blob/master/framework/db/ArrayExpression.php

ArrayExpression 類別代表一個陣列 SQL 表達式。

此類型的表達式也可以在條件中使用

$query->andWhere(['@>', 'items', new ArrayExpression([1, 2, 3], 'integer')])

根據 DBMS 的不同,這將產生一個準備完善的條件。例如,在 PostgreSQL 中,它將被編譯為 WHERE "items" @> ARRAY[1, 2, 3]::integer[]

方法詳情

隱藏繼承的方法

__construct() 公共方法

ArrayExpression 建構子。

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

陣列內容。可以表示為值陣列或傳回這些值的查詢。單一值將被視為包含一個元素的陣列。

$type string|null

陣列元素的類型。預設為 null,表示類型未明確指定。如果類型未明確指定,且 DBMS 無法從上下文中猜測,則會引發 SQL 錯誤。

$dimension integer

選擇元素所需的索引數量

                public function __construct($value, $type = null, $dimension = 1)
{
    if ($value instanceof self) {
        $value = $value->getValue();
    }
    $this->value = $value;
    $this->type = $type;
    $this->dimension = $dimension;
}

            
count() public method (自 2.0.14 版本起可用)

計算物件的元素

public integer count ( )
return integer

自訂計數作為整數。

傳回值會被轉換為整數。

                #[\ReturnTypeWillChange]
public function count()
{
    return count($this->value);
}

            
getDimension() public method

public integer getDimension ( )
return integer

選擇元素所需的索引數量

                public function getDimension()
{
    return $this->dimension;
}

            
getIterator() public method (自 2.0.14.1 版本起可用)

檢索外部迭代器

public Traversable getIterator ( )
return Traversable

實作 IteratorTraversable 的物件實例

throws yii\base\InvalidConfigException

當 ArrayExpression 包含 QueryInterface 物件時

                #[\ReturnTypeWillChange]
public function getIterator()
{
    $value = $this->getValue();
    if ($value instanceof QueryInterface) {
        throw new InvalidConfigException('The ArrayExpression class can not be iterated when the value is a QueryInterface object');
    }
    if ($value === null) {
        $value = [];
    }
    return new \ArrayIterator($value);
}

            
getType() public method

public string|null getType ( )

                public function getType()
{
    return $this->type;
}

            
getValue() public method

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

                public function getValue()
{
    return $this->value;
}

            
offsetExists() public method (自 2.0.14 版本起可用)

偏移量是否存在

public boolean offsetExists ( $offset )
$offset mixed

要檢查的偏移量。

return boolean

成功時為 True,失敗時為 false。

如果傳回非布林值,則傳回值將被轉換為布林值。

                #[\ReturnTypeWillChange]
public function offsetExists($offset)
{
    return isset($this->value[$offset]);
}

            
offsetGet() public method (自 2.0.14 版本起可用)

要檢索的偏移量

public mixed offsetGet ( $offset )
$offset mixed

要檢索的偏移量。

return mixed

可以傳回所有值類型。

                #[\ReturnTypeWillChange]
public function offsetGet($offset)
{
    return $this->value[$offset];
}

            
offsetSet() public method (自 2.0.14 版本起可用)

要設定的偏移量

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

要將值指派到的偏移量。

$value mixed

要設定的值。

                #[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
    $this->value[$offset] = $value;
}

            
offsetUnset() public method (自 2.0.14 版本起可用)

要取消設定的偏移量

public void offsetUnset ( $offset )
$offset mixed

要取消設定的偏移量。

                #[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
    unset($this->value[$offset]);
}