php8.5
Home/ Manual/ spl / arrayiterator/ ArrayIterator::current

ArrayIterator::current

PHP function Edit on GitHub ✎

(PHP 5, PHP 7, PHP 8)

Return current array entry

Description

ArrayIterator::current(): mixed

Get the current array entry.

Parameters Parameters

Return Values

The current array entry.

Examples

ArrayIterator::current() example

php
<?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 above example will output:

output
1 => one
2 => two
3 => three

Source: reference/spl/arrayiterator/current.xml · from the official PHP manual (php/doc-en)