Open In App

PHP | ArrayIterator next() Function

Last Updated : 21 Nov, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The ArrayIterator::next() function is an inbuilt function in PHP which is used to move the iterator to the next entry. Syntax:
void ArrayIterator::next( void )
Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs illustrate the ArrayIterator::next() function in PHP: Program 1: php
<?php
  
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
    array('G', 'e', 'e', 'k', 's', 'f', 'o', 'r')
);
 
// Display the elements
while($arrItr->valid()) {
    echo $arrItr->current();
    $arrItr->next();
}
  
?>
Output:
Geeksfor
Program 2: php
<?php
  
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
    array("Geeks", "for", "Geeks")
);
  
// Display value of array iterator
echo $arrItr->current() . "\n";

// Use next() function to move
// element into next position
$arrItr->next();

// Display value of array iterator
echo $arrItr->current() . "\n";

// Use next() function to move
// element into next position
$arrItr->next();

// Display value of array iterator
echo $arrItr->current();
  
?>
Output:
Geeks
for
Geeks
Reference: https://www.php.net/manual/en/arrayiterator.next.php

Next Article

Similar Reads