Monday, December 22, 2025
HomeLanguagesPHP | ArrayIterator append() Function

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:




<?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();
}
   
?>


Output:

Geeks123

Program 2:




<?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";
}
   
?>


Output:

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

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

RELATED ARTICLES

Most Popular

Dominic
32456 POSTS0 COMMENTS
Milvus
111 POSTS0 COMMENTS
Nango Kala
6823 POSTS0 COMMENTS
Nicole Veronica
11958 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12038 POSTS0 COMMENTS
Shaida Kate Naidoo
6958 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6911 POSTS0 COMMENTS
Umr Jansen
6890 POSTS0 COMMENTS