PHP Classes

File: doc/README

Recommend this page to a friend!
  Classes of Richard Williams   Aliased Array   doc/README   Download  
File: doc/README
Role: Documentation
Content type: text/plain
Description: Readme
Class: Aliased Array
Assign array entries that point to other entries
Author: By
Last change: New
Date: 8 years ago
Size: 1,786 bytes
 

Contents

Class file image Download
* Extends ArrayObject to implement a aliased key array. Allows for any number of * unique keys (alias keys) pointing to an array element. * * CAUTION: This will not handle multi-dimension arrays like you can't * do this: * * $a = new AliasedArray(); * $a[1][2] = 25; * * This will not work and will not generate an error. * * To add an element you first have to add an indexed data element * * $a = new AliasedArray(); * $a->set(key, data); * $a[key] = data; * * You can also add an existing array: * * $a = new AliasedArray($existingArray); * * After an element has been added you can add an alias for the key. The * alias is not allowed to match a key. * * $a->alias(key, alias); * * The following would throw an exception: * * $a->set('a', 10); * $a->set('b', 20); * $a->alias('a', 'b'); * * because the alias 'a' is already used as a key. * If the key does not exist, an exception will be thrown. * So for example these will work: * * $a->set(1, 'thedata'); * $a->alias(1, 'theabc'); * or * $a['key1'] = 'newdata'; * $a->alias('key1', 'alias1'); * * To get the data * * $a->get(1); // returns 'thedata' * $a[1]; // ditto * $a['key1']; // returns 'newdata' * $a['alias1']; // ditto * * if the element for the key or the index does not exist then a * NULL will be returned. You can unset key and alias(es). If you unset * by key then the key/value will be unset and any aliases pointing to the * value will be unset. If you unset an alias only that alias will be unset. * * unset($a['key1']); * unset($a['alias1']); * * Iterators iterate across the key array and ignore the alias array.