PHP | ArrayIterator append() Function
Last Updated :
21 Nov, 2019
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
$arrItr = new ArrayIterator(
array ( 'G' , 'e' , 'e' , 'k' , 's' )
);
$arrItr ->append( "123" );
while ( $arrItr ->valid()) {
echo $arrItr ->current();
$arrItr ->next();
}
?>
|
Program 2:
<?php
$arrItr = new ArrayIterator(
array (
"a" => "Geeks" ,
"b" => "for" ,
"c" => "Geeks"
)
);
$arrItr ->append( "Computer" );
$arrItr ->append( "Science" );
$arrItr ->append( "Portal" );
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...