Thursday, September 25, 2025
HomeLanguagesPHP | AppendIterator __construct() Function

PHP | AppendIterator __construct() Function

The AppendIterator::__construct() function is an inbuilt function in PHP which is used to construct an AppendIterator.

Syntax:

public AppendIterator::__construct( void )

Parameters: This function does not accept any parameters.

Return Value: This function does not return any value.

Below programs illustrate the AppendIterator::__construct() function in PHP:

Program 1:




<?php
  
// Declare an ArrayIterator
$arr1 = new ArrayIterator(array('G', 'e', 'e', 'k', 's'));
$arr2 = new ArrayIterator(array('f', 'o', 'r'));
$arr3 = new ArrayIterator(array('G', 'e', 'e', 'k', 's'));
  
// Create a new AppendIterator
$itr = new AppendIterator;
$itr->append($arr1);
$itr->append($arr2);
$itr->append($arr3);
  
// Display the result
foreach ($itr as $key => $val) {
    echo $key . " => " . $val . PHP_EOL;
}
  
?>


Output:

0 => G
1 => e
2 => e
3 => k
4 => s
0 => f
1 => o
2 => r
0 => G
1 => e
2 => e
3 => k
4 => s

Program 2:




<?php
  
// Declare an ArrayIterator
$arr1 = new ArrayIterator(array("Geeks", "for", "Geeks"));
$arr2 = new ArrayIterator(array("Computer", "Science", "Portal"));
  
// Create a new AppendIterator
$itr = new AppendIterator;
$itr->append($arr1);
$itr->append($arr2);
  
// Display the result
foreach ($itr as $key => $val) {
    echo $key . " => " . $val . PHP_EOL;
}
  
?>


Output:

0 => Geeks
1 => for
2 => Geeks
0 => Computer
1 => Science
2 => Portal

Reference: https://www.php.net/manual/en/appenditerator.construct.php

RELATED ARTICLES

Most Popular

Dominic
32319 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6682 POSTS0 COMMENTS
Nicole Veronica
11854 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6795 POSTS0 COMMENTS
Ted Musemwa
7071 POSTS0 COMMENTS
Thapelo Manthata
6753 POSTS0 COMMENTS
Umr Jansen
6761 POSTS0 COMMENTS