Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store


(PHP 5 >= 5.1.0)

RecursiveArrayIterator::getChildrenReturns an iterator for the current entry if it is an array or an object.


public RecursiveArrayIterator RecursiveArrayIterator::getChildren ( void )

Returns an iterator for the current iterator entry.


This function has no parameters.

Return Values

An iterator for the current entry, if it is an array or object.


An InvalidArgumentException will be thrown if the current entry does not contain an array or an object.


Example #1 RecursiveArrayIterator::getChildren() example

= array("a" => "lemon""b" => "orange", array("a" => "apple""p" => "pear"));

$iterator = new RecursiveArrayIterator($fruits);

while (
$iterator->valid()) {

    if (
$iterator->hasChildren()) {
// print all children
foreach ($iterator->getChildren() as $key => $value) {
$key ' : ' $value "\n";
    } else {
"No children.\n";


The above example will output:

No children.
No children.
a : apple
p : pear

See Also

PHP Manual