Get current array entry with ArrayIterator::current in PHP

Description

The following code shows how to get current array entry with ArrayIterator::current.

Example


// www .j  a v  a2 s.c  o m
<?php
$array = array('1' => 'one',
               '2' => 'two',
               '3' => 'three');

$arrayobject = new ArrayObject($array);

for($iterator = $arrayobject->getIterator();$iterator->valid();$iterator->next()) {
    echo $iterator->key() . ' => ' . $iterator->current() . "\n";
}
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone