Skip to content
Related Articles

Related Articles

PHP | ArrayIterator next() Function

Improve Article
Save Article
Like Article
  • Last Updated : 21 Nov, 2019

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


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!