Q:

Why does PHP have iterator objects?

I stumbled onto this PHP: Iterators page today and am wondering why these classes are even needed.  I'd like to make the assumption that they serve a purpose, otherwise they wouldn't be in PHP.  I'm struggling to see the benefit of such items when there are already very simple ways of doing these.
Is PHP making an error to be a more respectable/object oriented programming language?  Or is there really a benefit to doing this?
A good example of how there's 2 ways of doing this was found in a PHP comment on the ArrayIterator:
<?php
$fruits = array(
    "apple" => "yummy",
    "orange" => "ah ya, nice",
    "grape" => "wow, I love it!",
    "plum" => "nah, not me"
);
$obj = new ArrayObject( $fruits );
$it = $obj->getIterator();

// How many items are we iterating over?
echo "Iterating over: " . $obj->count() . " values\n";

// Iterate over the values in the ArrayObject:
while( $it->valid() ) {
    echo $it->key() . "=" . $it->current() . "\n";
    $it->next();
}

// The good thing here is that it can be iterated with foreach loop

foreach ($it as $key=>$val)
echo $key.":".$val."\n";

/* Outputs something like */

Iterating over: 4 values
apple=yummy
orange=ah ya, nice
grape=wow, I love it!
plum=nah, not me

?>

A:

Iterators are included in PHP because it lets you use common language constructs (such as foreach) with arbitrary objects, instead of being restricted to looping over built-in objects like arrays. It's a hassle (and breaks encapsulation) to force an object to transform it's internal state into an array for you to iterate over, and for large datasets can make your system run out of memory. An iterable lets you get past both of those issues by letting the object itself return individual elements only when requested.

