MemoizableArray ​
- Type
- Class
- Namespace
- craft\base
- Inherits
- craft\base\MemoizableArray
- Implements
- ArrayAccess, Countable, IteratorAggregate, craft\base\Serializable
- Since
- 3.5.8
MemoizableArray represents an array of values that need to be run through craft\helpers\ArrayHelper::where() or craft\helpers\ArrayHelper::firstWhere() repeatedly, where it could be beneficial if the results were memoized.
Any class properties that are set to an instance of this class should be excluded from class serialization:
public function __serialize()
{
$vars = get_object_vars($this);
unset($vars['myMemoizedPropertyName'];
return $vars;
}
Public Methods ​
Method | Description |
---|---|
__construct() | |
all() | Returns all items. |
append() | Appends the value |
asort() | Sort the entries by value |
count() | Get the number of public properties in the ArrayObject |
exchangeArray() | Exchange the array for another one. |
firstWhere() | Returns the first value where a given key (the name of a sub-array key or sub-object property) is set to a given value. |
getArrayCopy() | Creates a copy of the ArrayObject. |
getFlags() | Gets the behavior flags. |
getIterator() | Create a new iterator from an ArrayObject instance |
getIteratorClass() | Gets the iterator classname for the ArrayObject. |
ksort() | Sort the entries by key |
natcasesort() | Sort an array using a case insensitive "natural order" algorithm |
natsort() | Sort entries using a "natural order" algorithm |
offsetExists() | Returns whether the requested index exists |
offsetGet() | Returns the value at the specified index |
offsetSet() | Sets the value at the specified index to newval |
offsetUnset() | Unsets the value at the specified index |
serialize() | Serialize an ArrayObject |
setFlags() | Sets the behavior flags. |
setIteratorClass() | Sets the iterator classname for the ArrayObject. |
uasort() | Sort the entries with a user-defined comparison function and maintain key association |
uksort() | Sort the entries by keys using a user-defined comparison function |
unserialize() | Unserialize an ArrayObject |
where() | Filters the array to only the values where a given key (the name of a sub-array key or sub-object property) is set to a given value. |
whereIn() | Filters the array to only the values where a given key (the name of a sub-array key or sub-object property) is set to one of a given range of values. |
__construct()
​
Arguments ​
all()
​
Returns all items.
Returns ​
\craft\base\T[]
append()
​
Appends the value
See also https://www.php.net/manual/en/arrayobject.append.phpView source
Arguments ​
$value
asort()
​
Sort the entries by value
See also https://www.php.net/manual/en/arrayobject.asort.phpView source
Arguments ​
$sort_flags
count()
​
Get the number of public properties in the ArrayObject
See also https://www.php.net/manual/en/arrayobject.count.phpView source
exchangeArray()
​
Exchange the array for another one.
See also https://www.php.net/manual/en/arrayobject.exchangearray.phpView source
Arguments ​
$input
firstWhere()
​
Returns the first value where a given key (the name of a sub-array key or sub-object property) is set to a given value.
Arguments ​
$key
(string) – The column name whose result will be used to index the array$value
(mixed
) – The value that$key
should be compared with$strict
(boolean) – Whether a strict type comparison should be used when checking array element values against$value
Returns ​
\craft\base\T
– The first matching value, or null
if no match is found
getArrayCopy()
​
Creates a copy of the ArrayObject.
See also https://www.php.net/manual/en/arrayobject.getarraycopy.phpView source
getFlags()
​
Gets the behavior flags.
See also https://www.php.net/manual/en/arrayobject.getflags.phpView source
getIterator()
​
Create a new iterator from an ArrayObject instance
See also https://www.php.net/manual/en/arrayobject.getiterator.phpView source
getIteratorClass()
​
Gets the iterator classname for the ArrayObject.
See also https://www.php.net/manual/en/arrayobject.getiteratorclass.phpView source
ksort()
​
Sort the entries by key
See also https://www.php.net/manual/en/arrayobject.ksort.phpView source
Arguments ​
$sort_flags
natcasesort()
​
Sort an array using a case insensitive "natural order" algorithm
See also https://www.php.net/manual/en/arrayobject.natcasesort.phpView source
natsort()
​
Sort entries using a "natural order" algorithm
See also https://www.php.net/manual/en/arrayobject.natsort.phpView source
offsetExists()
​
Returns whether the requested index exists
See also https://www.php.net/manual/en/arrayobject.offsetexists.phpView source
Arguments ​
$offset
offsetGet()
​
Returns the value at the specified index
See also https://www.php.net/manual/en/arrayobject.offsetget.phpView source
Arguments ​
$offset
offsetSet()
​
Sets the value at the specified index to newval
See also https://www.php.net/manual/en/arrayobject.offsetset.phpView source
Arguments ​
$offset
$value
offsetUnset()
​
Unsets the value at the specified index
See also https://www.php.net/manual/en/arrayobject.offsetunset.phpView source
Arguments ​
$offset
serialize()
​
Serialize an ArrayObject
See also https://www.php.net/manual/en/arrayobject.serialize.phpView source
setFlags()
​
Sets the behavior flags.
See also https://www.php.net/manual/en/arrayobject.setflags.phpView source
Arguments ​
$flags
setIteratorClass()
​
Sets the iterator classname for the ArrayObject.
See also https://www.php.net/manual/en/arrayobject.setiteratorclass.phpView source
Arguments ​
$iteratorClass
uasort()
​
Sort the entries with a user-defined comparison function and maintain key association
See also https://www.php.net/manual/en/arrayobject.uasort.phpView source
Arguments ​
$cmp_function
uksort()
​
Sort the entries by keys using a user-defined comparison function
See also https://www.php.net/manual/en/arrayobject.uksort.phpView source
Arguments ​
$cmp_function
unserialize()
​
Unserialize an ArrayObject
See also https://www.php.net/manual/en/arrayobject.unserialize.phpView source
Arguments ​
$data
where()
​
Filters the array to only the values where a given key (the name of a sub-array key or sub-object property) is set to a given value.
Array keys are preserved by default.
Arguments ​
$key
(string) – The column name whose result will be used to index the array$value
(mixed
) – The value that$key
should be compared with$strict
(boolean) – Whether a strict type comparison should be used when checking array element values against$value
Returns ​
self
– The filtered array
whereIn()
​
Filters the array to only the values where a given key (the name of a sub-array key or sub-object property) is set to one of a given range of values.
Array keys are preserved by default.
Arguments ​
$key
(string) – The column name whose result will be used to index the array$values
(array) – The value that$key
should be compared with$strict
(boolean) – Whether a strict type comparison should be used when checking array element values against$values
Returns ​
self
– The filtered array