# 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

- IteratorAggregate::getIterator — Retrieve an external iterator or traversable

`↑` and `↓` to navigate • `Enter` to select • `Esc` to close • `/` to open