MemoizableArray

Type
Class
Namespace
craft\base
Inherits
craft\base\MemoizableArray » ArrayObject
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

# Public Methods

Method Description
all() Returns all items.
append()
asort()
exchangeArray()
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.
ksort()
natcasesort()
natsort()
offsetSet()
offsetUnset()
uasort()
uksort()
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.

# all()

Returns all items.

View source

Returns

array

# append()

View source

Arguments

  • $value

# asort()

View source

Arguments

  • $sort_flags

# exchangeArray()

View 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.

View source

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

mixed – The first matching value, or null if no match is found

# ksort()

View source

Arguments

  • $sort_flags

# natcasesort()

View source

# natsort()

View source

# offsetSet()

View source

Arguments

  • $index
  • $newval

# offsetUnset()

View source

Arguments

  • $index

# uasort()

View source

Arguments

  • $cmp_function

# uksort()

View source

Arguments

  • $cmp_function

# 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

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.

View source

Arguments

  • $key (string) – The column name whose result will be used to index the array
  • $values (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 $values

Returns

self – The filtered array