The following are common functions for arrayobject:
Arrayiterator::current (void)//returns the current array element
Arrayiterator::key (void)//Returns the current array key
Arrayiterator::next (void)//refers to the down-number-group element
Arrayiterator::rewind (void)//reset array pointer to head
Arrayiterator::seek ()//Find a location in an array
Arrayiterator::valid ()//check if the array also contains other elements
Arrayobject::append ()//Add new element
Arrayobject::__construct ()//construct a new Array object
Arrayobject::count ()//Returns the number of elements in the iterator
Arrayobject::getiterator ()//construct a new iterator from an array object
Arrayobject::offsetexists (mixed index)//determine if the submitted value exists
Arrayobject::offsetget ()//Specify name to get the value
Arrayobject::offsetset ()//Modify the value of the specified name
Arrayobject::offsetunset ()//delete data
Example 1: Print all elements of an array
<?php
$array = Array (' 1 ' = ' one ',
' 2 ' = ' both ',
' 3 ' = ' three ');
$arrayobject = new Arrayobject ($array); Constructs a Arrayobject object
for ($iterator = $arrayobject->getiterator ();//Constructs an iterator
$iterator->valid ();//Check if the element is still included
$iterator->next ()) {//points to the next element
echo $iterator->key (). ' = '. $iterator->current (). "\ n";//print array elements
}
?>
Example 2: Resetting an array pointer
<?php
$arrayobject = new Arrayobject ();
$arrayobject [] = ' zero ';
$arrayobject [] = ' one ';
$arrayobject [] = ' both ';
$iterator = $arrayobject->getiterator ();
$iterator->next ();
echo $iterator->key (); 1
$iterator->rewind (); Reset the pointer to the head
echo $iterator->key (); 0
?>
PHP Standard library Arrayobject