Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<Iterator::validIteratorAggregate::getIterator>
^Predefined Interfaces and ClassesLast updated: Mon, 26 Oct 2026

The IteratorAggregate interface

(PHP 5, PHP 7, PHP 8)

Introduction

Interface to create an external Iterator.

Interface synopsis

interface IteratorAggregate extends Traversable {
/* Methods */
public function getIterator(): Traversable
}

Examples

Example #1 Basic usage

<?php

class myData implements IteratorAggregate
{
    public function getIterator(): Traversable
    {
        return new ArrayIterator([
            "key one" => "item one",
            "key two" => "item two",
            "key three" => "item three"
        ]);
    }
}

$obj = new myData();

foreach ($obj as $key => $value) {
    var_dump($key, $value);
    echo "\n";
}

The above example will output something similar to:

string(7) "key one"
string(8) "item one"

string(7) "key two"
string(8) "item two"

string(9) "key three"
string(10) "item three"

Table of Contents


<Iterator::validIteratorAggregate::getIterator>
^Predefined Interfaces and ClassesLast updated: Mon, 26 Oct 2026