- Home
- About
- Testimonials
- Demos
- Download
- Documentation
- Blogs
- Forum
- Support

Packages:
default
System
System.Caching
System.Collections
System.Data
System.Data.ActiveRecord
System.Data.ActiveRecord.Relations
System.Data.ActiveRecord.Scaffold
System.Data.ActiveReecord.Scaffold.InputBuilder
System.Data.Commom.Sqlite
System.Data.Common
System.Data.Common.Mssql
System.Data.Common.Mysql
System.Data.Common.Oracle
System.Data.Common.Pgsql
System.Data.Common.Sqlite
System.Data.DataGateway
System.Data.SqlMap
System.Data.SqlMap.Configuration
System.Data.SqlMap.Statements
System.Exceptions
System.I18N
System.IO
System.Security
System.Util
System.Web
System.Web.Services
System.Web.UI
System.Web.UI.ActiveControls
System.Web.UI.WebControls
System.Web.UI.WebControls.assets
System.Xml
Classes:
TAttributeCollection
TDummyDataSource
TDummyDataSourceIterator
TList
TListIterator
TMap
TMapIterator
TPagedDataSource
TPagedList
TPagedListFetchDataEventParameter
TPagedListIterator
TPagedListPageChangedEventParameter
TPagedMapIterator
TQueue
TQueueIterator
TStack
TStackIterator

Keyword

# Class TMap

    TComponent
       |
       --TMap

#### Direct Known Sub-classes:

TAttributeCollection

TMap class

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

Since: 3.0
Author: Qiang Xue <qiang.xue@gmail.com>

Constructor Summary
public | __construct Array Constructor.

Method Summary
void | add ( mixed $key, mixed $value) Adds an item into the map.
void | clear () Removes all items in the map.
boolean | contains ( mixed $key)
void | copyFrom ( mixed $data) Copies iterable data into the map.
integer | count () Returns the number of items in the map.
integer | getCount ()
Iterator | getIterator () Returns an iterator for traversing the items in the list.
array | getKeys ()
boolean | getReadOnly ()
mixed | itemAt ( mixed $key) Returns the item with the specified key.
void | mergeWith ( mixed $data) Merges iterable data into the map.
boolean | offsetExists ( mixed $offset) Returns whether there is an element at the specified offset.
mixed | offsetGet ( integer $offset) Returns the element at the specified offset.
void | offsetSet ( integer $offset, mixed $item) Sets the element at the specified offset.
void | offsetUnset ( mixed $offset) Unsets the element at the specified offset.
mixed | remove ( mixed $key) Removes an item from the map by its key.
protected void | setReadOnly ( boolean $value)
array | toArray ()

Methods Inherited From TComponent

TComponent::addParsedObject(), TComponent::attachEventHandler(), TComponent::canGetProperty(), TComponent::canSetProperty(), TComponent::createdOnTemplate(), TComponent::detachEventHandler(), TComponent::evaluateExpression(), TComponent::evaluateStatements(), TComponent::getEventHandlers(), TComponent::getSubProperty(), TComponent::hasEvent(), TComponent::hasEventHandler(), TComponent::hasProperty(), TComponent::raiseEvent(), TComponent::setSubProperty(), TComponent::__get(), TComponent::__set()

Constructor Details

## __construct

public __construct | Array

Constructor.

Initializes the list with an array or an iterable object.

Throws: TInvalidDataTypeException If data is not null and neither an array nor an iterator.

Method Details

## add

public void add | (mixed $key , mixed $value )

Adds an item into the map.

Note, if the specified key already exists, the old value will be overwritten.

Input
mixed | $key | key
mixed | $value | value
Output
Exception
throws | TInvalidOperationException if the map is read-only

## clear

public void clear | ()

Removes all items in the map.

Output
Exception

## contains

public boolean contains | (mixed $key )

Input
mixed | $key | the key
Output
boolean | whether the map contains an item with the specified key
Exception

## copyFrom

public void copyFrom | (mixed $data )

Copies iterable data into the map.

Note, existing data in the map will be cleared first.

Input
mixed | $data | the data to be copied from, must be an array or object implementing Traversable
Output
Exception
throws | TInvalidDataTypeException If data is neither an array nor an iterator.

## count

public integer count | ()

Returns the number of items in the map.

This method is required by Countable interface.

Output
integer | number of items in the map.
Exception

## getCount

public integer getCount | ()

Output
integer | the number of items in the map
Exception

## getIterator

public Iterator getIterator | ()

Returns an iterator for traversing the items in the list.

This method is required by the interface IteratorAggregate.

Output
Iterator | an iterator for traversing the items in the list.
Exception

## getKeys

public array getKeys | ()

Output
array | the key list
Exception

## getReadOnly

public boolean getReadOnly | ()

Output
boolean | whether this map is read-only or not. Defaults to false.
Exception

## itemAt

public mixed itemAt | (mixed $key )

Returns the item with the specified key.

This method is exactly the same as offsetGet.

Input
mixed | $key | the key
Output
mixed | the element at the offset, null if no element is found at the offset
Exception

## mergeWith

public void mergeWith | (mixed $data )

Merges iterable data into the map.

Existing data in the map will be kept and overwritten if the keys are the same.

Input
mixed | $data | the data to be merged with, must be an array or object implementing Traversable
Output
Exception
throws | TInvalidDataTypeException If data is neither an array nor an iterator.

## offsetExists

public boolean offsetExists | (mixed $offset )

Returns whether there is an element at the specified offset.

This method is required by the interface ArrayAccess.

Input
mixed | $offset | the offset to check on
Output
Exception

## offsetGet

public mixed offsetGet | (integer $offset )

Returns the element at the specified offset.

This method is required by the interface ArrayAccess.

Input
integer | $offset | the offset to retrieve element.
Output
mixed | the element at the offset, null if no element is found at the offset
Exception

## offsetSet

public void offsetSet | (integer $offset , mixed $item )

Sets the element at the specified offset.

This method is required by the interface ArrayAccess.

Input
integer | $offset | the offset to set element
mixed | $item | the element value
Output
Exception

## offsetUnset

public void offsetUnset | (mixed $offset )

Unsets the element at the specified offset.

This method is required by the interface ArrayAccess.

Input
mixed | $offset | the offset to unset element
Output
Exception

## remove

public mixed remove | (mixed $key )

Removes an item from the map by its key.

Input
mixed | $key | the key of the item to be removed
Output
mixed | the removed value, null if no such key exists.
Exception
throws | TInvalidOperationException if the map is read-only

## setReadOnly

protected void setReadOnly | (boolean $value )

Input
boolean | $value | whether this list is read-only or not
Output
Exception

## toArray

public array toArray | ()

Output
array | the list of items in array
Exception