Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • CAttributeCollection
  • CConfiguration
  • CList
  • CListIterator
  • CMap
  • CMapIterator
  • CQueue
  • CQueueIterator
  • CStack
  • CStackIterator
  • CTypedList
  • CTypedMap
  • Overview
  • Package
  • Class
  • Tree

Class CMap

CMap implements a collection that takes key-value pairs.

You can access, add or remove an item with a key by using CMap::itemAt(), CMap::add(), and CMap::remove(). To get the number of the items in the map, use CMap::getCount(). CMap 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
CComponent
Extended by CMap implements IteratorAggregate, ArrayAccess, Countable

Direct known subclasses

CAttributeCollection, CConfiguration, CCookieCollection, CFormElementCollection, CTypedMap
Package: system\collections
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/collections/CMap.php
Methods summary
public
# __construct( array $data = null, boolean $readOnly = false )

Constructor. Initializes the list with an array or an iterable object.

Constructor. Initializes the list with an array or an iterable object.

Parameters

$data
array
$data the initial data. Default is null, meaning no initialization.
$readOnly
boolean
$readOnly whether the list is read-only

Throws

CException
If data is not null and neither an array nor an iterator.
public boolean
# getReadOnly( )

Returns

boolean
whether this map is read-only or not. Defaults to false.
protected
# setReadOnly( boolean $value )

Parameters

$value
boolean
$value whether this list is read-only or not
public CMapIterator
# getIterator( )

Returns an iterator for traversing the items in the list. This method is required by the interface IteratorAggregate.

Returns an iterator for traversing the items in the list. This method is required by the interface IteratorAggregate.

Returns

CMapIterator
an iterator for traversing the items in the list.

Implementation of

IteratorAggregate::getIterator()
public integer
# count( )

Returns the number of items in the map. This method is required by Countable interface.

Returns the number of items in the map. This method is required by Countable interface.

Returns

integer
number of items in the map.

Implementation of

Countable::count()
public integer
# getCount( )

Returns the number of items in the map.

Returns the number of items in the map.

Returns

integer
the number of items in the map
public array
# getKeys( )

Returns

array
the key list
public mixed
# itemAt( mixed $key )

Returns the item with the specified key. This method is exactly the same as CMap::offsetGet().

Returns the item with the specified key. This method is exactly the same as CMap::offsetGet().

Parameters

$key
mixed
$key the key

Returns

mixed
the element at the offset, null if no element is found at the offset
public
# add( mixed $key, mixed $value )

Adds an item into the map. Note, if the specified key already exists, the old value will be overwritten.

Adds an item into the map. Note, if the specified key already exists, the old value will be overwritten.

Parameters

$key
mixed
$key key
$value
mixed
$value value

Throws

CException
if the map is read-only
public mixed
# remove( mixed $key )

Removes an item from the map by its key.

Removes an item from the map by its key.

Parameters

$key
mixed
$key the key of the item to be removed

Returns

mixed
the removed value, null if no such key exists.

Throws

CException
if the map is read-only
public
# clear( )

Removes all items in the map.

Removes all items in the map.

public boolean
# contains( mixed $key )

Parameters

$key
mixed
$key the key

Returns

boolean
whether the map contains an item with the specified key
public array
# toArray( )

Returns

array
the list of items in array
public
# copyFrom( mixed $data )

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

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

Parameters

$data
mixed
$data the data to be copied from, must be an array or object implementing Traversable

Throws

CException
If data is neither an array nor an iterator.
public
# mergeWith( mixed $data, boolean $recursive = true )

Merges iterable data into the map.

Merges iterable data into the map.

Existing elements in the map will be overwritten if their keys are the same as those in the source. If the merge is recursive, the following algorithm is performed:
  • the map data is saved as $a, and the source data is saved as $b;
  • if $a and $b both have an array indexed at the same string key, the arrays will be merged using this algorithm;
  • any integer-indexed elements in $b will be appended to $a and reindexed accordingly;
  • any string-indexed elements in $b will overwrite elements in $a with the same index;

Parameters

$data
mixed
$data the data to be merged with, must be an array or object implementing Traversable
$recursive
boolean
$recursive whether the merging should be recursive.

Throws

CException
If data is neither an array nor an iterator.
public static array
# mergeArray( array $a, array $b )

Merges two or more arrays into one recursively. If each array has an element with the same string key value, the latter will overwrite the former (different from array_merge_recursive). Recursive merging will be conducted if both arrays have an element of array type and are having the same key. For integer-keyed elements, the elements from the latter array will be appended to the former array.

Merges two or more arrays into one recursively. If each array has an element with the same string key value, the latter will overwrite the former (different from array_merge_recursive). Recursive merging will be conducted if both arrays have an element of array type and are having the same key. For integer-keyed elements, the elements from the latter array will be appended to the former array.

Parameters

$a
array
$a array to be merged to
$b
array
$b array to be merged from. You can specify additional arrays via third argument, fourth argument etc.

Returns

array
the merged array (the original arrays are not changed.)

See

CMap::mergeWith()
public boolean
# offsetExists( mixed $offset )

Returns whether there is an element at the specified offset. This method is required by the interface ArrayAccess.

Returns whether there is an element at the specified offset. This method is required by the interface ArrayAccess.

Parameters

$offset
mixed
$offset the offset to check on

Returns

boolean

Implementation of

ArrayAccess::offsetExists()
public mixed
# offsetGet( integer $offset )

Returns the element at the specified offset. This method is required by the interface ArrayAccess.

Returns the element at the specified offset. This method is required by the interface ArrayAccess.

Parameters

$offset
integer
$offset the offset to retrieve element.

Returns

mixed
the element at the offset, null if no element is found at the offset

Implementation of

ArrayAccess::offsetGet()
public
# offsetSet( integer $offset, mixed $item )

Sets the element at the specified offset. This method is required by the interface ArrayAccess.

Sets the element at the specified offset. This method is required by the interface ArrayAccess.

Parameters

$offset
integer
$offset the offset to set element
$item
mixed
$item the element value

Implementation of

ArrayAccess::offsetSet()
public
# offsetUnset( mixed $offset )

Unsets the element at the specified offset. This method is required by the interface ArrayAccess.

Unsets the element at the specified offset. This method is required by the interface ArrayAccess.

Parameters

$offset
mixed
$offset the offset to unset element

Implementation of

ArrayAccess::offsetUnset()
Methods inherited from CComponent
__call(), __get(), __isset(), __set(), __unset(), asa(), attachBehavior(), attachBehaviors(), attachEventHandler(), canGetProperty(), canSetProperty(), detachBehavior(), detachBehaviors(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), getEventHandlers(), hasEvent(), hasEventHandler(), hasProperty(), raiseEvent()
Magic properties summary
public boolean $readOnly
#

Whether this map is read-only or not. Defaults to false.

Whether this map is read-only or not. Defaults to false.

public CMapIterator $iterator
#

An iterator for traversing the items in the list.

An iterator for traversing the items in the list.

public integer $count
#

The number of items in the map.

The number of items in the map.

public array $keys
#

The key list.

The key list.

API documentation generated by ApiGen 2.8.0