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[]
.
ArrayExpression constructor.
public void __construct ( $value, $type = null, $dimension = 1 ) $value array|yii\db\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.
$type string|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.
The number of indices needed to select an element
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 elements of an object
public integer count ( ) return integerThe custom count as an integer.
The return value is cast to an integer.
public function count()
{
return count($this->value);
}
public function getDimension()
{
return $this->dimension;
}
Retrieve an external iterator
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);
}
public function getType()
{
return $this->type;
}
public function getValue()
{
return $this->value;
}
Whether a offset exists
public boolean offsetExists ( $offset ) $offset mixedAn offset to check for.
return booleanTrue on success or false on failure.
The return value will be casted to boolean if non-boolean was returned.
public function offsetExists($offset)
{
return isset($this->value[$offset]);
}
Offset to retrieve
public mixed offsetGet ( $offset ) $offset mixedThe offset to retrieve.
return mixedCan return all value types.
public function offsetGet($offset)
{
return $this->value[$offset];
}
Offset to set
public void offsetSet ( $offset, $value ) $offset mixedThe offset to assign the value to.
$value mixedThe value to set.
public function offsetSet($offset, $value)
{
$this->value[$offset] = $value;
}
Offset to unset
public void offsetUnset ( $offset ) $offset mixedThe offset to unset.
public function offsetUnset($offset)
{
unset($this->value[$offset]);
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4