Class yii\db\ArrayExpression
| 继承 | yii\db\ArrayExpression |
|---|---|
| 实现 | ArrayAccess, Countable, IteratorAggregate, yii\db\ExpressionInterface |
| 可用版本自 | 2.0.14 |
| 源码 | https://github.com/yiichina/yii2/blob/api/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 构造函数。 | yii\db\ArrayExpression |
| count() | 计算对象的元素 | yii\db\ArrayExpression |
| getDimension() | yii\db\ArrayExpression | |
| getIterator() | 检索外部迭代器 | yii\db\ArrayExpression |
| getType() | yii\db\ArrayExpression | |
| getValue() | yii\db\ArrayExpression | |
| offsetExists() | 是否存在偏移量 | yii\db\ArrayExpression |
| offsetGet() | 要检索的偏移量 | yii\db\ArrayExpression |
| offsetSet() | 偏移量设置 | yii\db\ArrayExpression |
| offsetUnset() | 删除偏移量 | yii\db\ArrayExpression |
方法详情
ArrayExpression 构造函数。
| public void __construct($value, $type = null, $dimension = 1) | ||
| $value | array|yii\db\QueryInterface|mixed | 数组内容。表示为值数组或返回这些值的 Query。 单个值将被视为包含一个元素的数组。 |
| $type | string|null | 数组元素的类型。默认为 |
| $dimension | integer | 选择元素所需的索引数 |
计算对象的元素
| public integer count() | ||
| return | integer | 自定义计数为整数。 返回值转换为整数。 |
|---|---|---|
参见 \yii\db\dimensions.
| public integer getDimension() | ||
| return | integer | 选择元素所需的索引数 |
|---|---|---|
检索外部迭代器
| public Traversable getIterator() | ||
| return | Traversable | 实现 迭代器 或 可遍历 的对象实例 |
|---|---|---|
| throws | yii\base\InvalidConfigException | 当 ArrayExpression 包含 QueryInterface 对象时 |
参见 \yii\db\type.
| public null|string getType() |
参见 \yii\db\value.
| public array|mixed|yii\db\QueryInterface getValue() |
是否存在偏移量
| public boolean offsetExists($offset) | ||
| $offset | mixed | 要检查的偏移量。 |
| return | boolean | 成功时为 true,失败为 false。 如果返回非布尔值,则返回值将被转换为 boolean。 |
|---|---|---|
要检索的偏移量
| public mixed offsetGet($offset) | ||
| $offset | mixed | 要检索的偏移量。 |
| return | mixed | 可以返回所有值类型。 |
|---|---|---|
偏移量设置
| public void offsetSet($offset, $value) | ||
| $offset | mixed | 要赋值的偏移量。 |
| $value | mixed | 要设置的值。 |
删除偏移量
| public void offsetUnset($offset) | ||
| $offset | mixed | 要删除的偏移量。 |