Class \Prado\Collections\TMap
TMap implements a collection that takes key-value pairs.
You can access, add or remove an item with a key by using itemAt, add, and remove. To get the number of the items in the map, use getCount. TMap can also be used like a regular array as follows,
$map[$key]=$value; // add a key-value pair
unset($map[$key]); // remove the value with the specified key
if(isset($map[$key])) // if the map contains the key
foreach($map as $key=>$value) // traverse the items in the map
$n=count($map); // returns the number of items in the map
Class hierarchy
- \Prado\Collections\TMap implements IteratorAggregate, ArrayAccess, Countable
- \Prado\TComponent
Since: 3.0
public
|
__construct([null|array<string|int, mixed>|Iterator $data = null ][, bool|null $readOnly = null ]) : mixed
Constructor.
Initializes the list with an array or an iterable object. |
public
|
add(mixed $key, mixed $value) : mixed
Adds an item into the map.
Note, if the specified key already exists, the old value will be overwritten. |
public
|
|
public
|
|
public
|
copyFrom(mixed $data) : void
Copies iterable data into the map.
Note, existing data in the map will be cleared first. |
public
|
count() : int
Returns the number of items in the map.
This method is required by \Countable interface. |
public
|
|
public
|
getIterator() : Iterator
Returns an iterator for traversing the items in the list.
This method is required by the interface \IteratorAggregate. |
public
|
|
public
|
|
public
|
itemAt(mixed $key) : mixed
Returns the item with the specified key.
This method is exactly the same as offsetGet. |
public
|
|
public
|
mergeWith(mixed $data) : void
Merges iterable data into the map.
Existing data in the map will be kept and overwritten if the keys are the same. |
public
|
offsetExists(mixed $offset) : bool
Returns whether there is an element at the specified offset.
This method is required by the interface \ArrayAccess. |
public
|
offsetGet(mixed $offset) : mixed
Returns the element at the specified offset.
This method is required by the interface \ArrayAccess. |
public
|
offsetSet(mixed $offset, mixed $item) : void
Sets the element at the specified offset.
This method is required by the interface \ArrayAccess. |
public
|
offsetUnset(mixed $offset) : void
Unsets the element at the specified offset.
This method is required by the interface \ArrayAccess. |
public
|
|
public
|
removeItem(mixed $item) : array<string|int, mixed>
Removes an item from the map. This removes all of an item from the map.
|
public
|
|
public
|
|
protected
|
_getZappableSleepProps(array<string|int, mixed> &$exprops) : mixed
Returns an array with the names of all variables of this object that should NOT be serialized
because their value is the default one or useless to be cached for the next page loads.
Reimplement in derived classes to add new variables, but remember to also to call the parent implementation first. |
protected
|
\Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |