Open In App

PHP | ArrayIterator next() Function

Last Updated : 21 Nov, 2019
Improve
Improve
Like Article
Like
Save
Share
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
    
// 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
    
// 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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads