PHP | ArrayIterator append() Function

The ArrayIterator::append() function is an inbuilt function in PHP which is used to append an element into an array iterator.

Syntax:

void ArrayIterator::append( mixed $value )

Parameters: This function accepts single parameter $value that holds the value that need to be append.



Return Value: This function does not return any value.

Below programs illustrate the ArrayIterator::append() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
   
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
    array('G', 'e', 'e', 'k', 's')
);
   
// Append the element into array iterator
$arrItr->append("123");
  
// Display the elements
while($arrItr->valid()) {
    echo $arrItr->current();
    $arrItr->next();
}
   
?>

chevron_right


Output:

Geeks123

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
   
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
    array(
        "a" => "Geeks",
        "b" => "for",
        "c" => "Geeks"
    )
);
   
// Append the array element
$arrItr->append("Computer");
$arrItr->append("Science");
$arrItr->append("Portal");
   
// Display the elements
foreach ($arrItr as $key => $val) {
    echo $key . " => " . $val . "\n";
}
   
?>

chevron_right


Output:

a => Geeks
b => for
c => Geeks
0 => Computer
1 => Science
2 => Portal

Reference: https://www.php.net/manual/en/arrayiterator.append.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.