MemoizableArray
- Type
- Class
- Namespace
- craft\base
- Inherits
- craft\base\MemoizableArray
- Implements
- ArrayAccess (opens new window), Countable (opens new window), IteratorAggregate (opens new window), 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;
}
View source (opens new window)
# 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()
View source (opens new window)
Arguments
$array
(array (opens new window), object (opens new window))$flags
(integer (opens new window))$iteratorClass
(string (opens new window))
# all()
Returns all items.
View source (opens new window)
Returns
\craft\base\T[]
# append()
Appends the value
See also https://www.php.net/manual/en/arrayobject.append.php View source (opens new window)
Arguments
$value
# asort()
Sort the entries by value
See also https://www.php.net/manual/en/arrayobject.asort.php View source (opens new window)
Arguments
$sort_flags
# count()
Get the number of public properties in the ArrayObject
See also https://www.php.net/manual/en/arrayobject.count.php View source (opens new window)
# exchangeArray()
Exchange the array for another one.
See also https://www.php.net/manual/en/arrayobject.exchangearray.php View source (opens new window)
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.
View source (opens new window)
Arguments
$key
(string (opens new window)) – The column name whose result will be used to index the array$value
(mixed
) – The value that$key
should be compared with$strict
(boolean (opens new window)) – 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.php View source (opens new window)
# getFlags()
Gets the behavior flags.
See also https://www.php.net/manual/en/arrayobject.getflags.php View source (opens new window)
# getIterator()
Create a new iterator from an ArrayObject instance
See also https://www.php.net/manual/en/arrayobject.getiterator.php View source (opens new window)
# getIteratorClass()
Gets the iterator classname for the ArrayObject.
See also https://www.php.net/manual/en/arrayobject.getiteratorclass.php View source (opens new window)
# ksort()
Sort the entries by key
See also https://www.php.net/manual/en/arrayobject.ksort.php View source (opens new window)
Arguments
$sort_flags
# natcasesort()
Sort an array using a case insensitive "natural order" algorithm
See also https://www.php.net/manual/en/arrayobject.natcasesort.php View source (opens new window)
# natsort()
Sort entries using a "natural order" algorithm
See also https://www.php.net/manual/en/arrayobject.natsort.php View source (opens new window)
# offsetExists()
Returns whether the requested index exists
See also https://www.php.net/manual/en/arrayobject.offsetexists.php View source (opens new window)
Arguments
$offset
# offsetGet()
Returns the value at the specified index
See also https://www.php.net/manual/en/arrayobject.offsetget.php View source (opens new window)
Arguments
$offset
# offsetSet()
Sets the value at the specified index to newval
See also https://www.php.net/manual/en/arrayobject.offsetset.php View source (opens new window)
Arguments
$offset
$value
# offsetUnset()
Unsets the value at the specified index
See also https://www.php.net/manual/en/arrayobject.offsetunset.php View source (opens new window)
Arguments
$offset
# serialize()
Serialize an ArrayObject
See also https://www.php.net/manual/en/arrayobject.serialize.php View source (opens new window)
# setFlags()
Sets the behavior flags.
See also https://www.php.net/manual/en/arrayobject.setflags.php View source (opens new window)
Arguments
$flags
# setIteratorClass()
Sets the iterator classname for the ArrayObject.
See also https://www.php.net/manual/en/arrayobject.setiteratorclass.php View source (opens new window)
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.php View source (opens new window)
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.php View source (opens new window)
Arguments
$cmp_function
# unserialize()
Unserialize an ArrayObject
See also https://www.php.net/manual/en/arrayobject.unserialize.php View source (opens new window)
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.
View source (opens new window)
Arguments
$key
(string (opens new window)) – The column name whose result will be used to index the array$value
(mixed
) – The value that$key
should be compared with$strict
(boolean (opens new window)) – 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.
View source (opens new window)
Arguments
$key
(string (opens new window)) – The column name whose result will be used to index the array$values
(array (opens new window)) – The value that$key
should be compared with$strict
(boolean (opens new window)) – Whether a strict type comparison should be used when checking array element values against$values
Returns
self
– The filtered array