_array Documentation

0.1

_array is an object oriented interface to php arrays API. Arrays API is wrapped in the class _array, which implements ArrayAccess and IteratorAggregate, so that it can be used transparently like an ordinary php array:

$a = new _array('foo', 'bar');
$a[] = 'baz';
foreach($a as $t) echo $t; #

The 'new' in the above can be omitted, making it look even more "php'ish".

_array also provides a meaningful toString method:

$nested = _array(
        'a', 
        'b',
        _array(
                'c',
                _array('x')
        )
);

echo $nested; # "a, b, c, x"

Most _array methods return objects of class _array, thus enabling method chaining:

echo $files->select('is_readable')->map('ucfirst')->natsort()->join("<br>"); #

It's worth noting that every method call creates a new object:

$a = new _array('c', 'a', 'b');
$b = $a->sort();

echo $a; # "c, a, b"
echo $b; # "a, b, c"

Exception are few modificator methods like _array::pop().

Along with main class the package contains a set of utility functions that provide syntactic sugar for creating _array objects from different sources:

$ary     = _array('one', 'two');
$server  = _a($_SERVER);
$words   = _w('foo bar baz');

_array Class Reference

utility functions


Generated on Mon Jun 2 18:18:39 2008 for _array by  doxygen 1.5.5