PHP | ArrayIterator getArrayCopy() Function
Last Updated :
21 Nov, 2019
The ArrayIterator::getArrayCopy() function is an inbuilt function in PHP which is used to create a copy of an array.
Syntax:
array ArrayIterator::getArrayCopy( void )
Parameters: This function does not accept any parameters.
Return Value: This function returns the copy of array.
Below programs illustrate the ArrayIterator::getArrayCopy() function in PHP:
Program 1:
<?php
$arrItr = new ArrayIterator(
array ( 'G' , 'e' , 'e' , 'k' , 's' , 'f' , 'o' , 'r' )
);
$copyArr = $arrItr ->getArrayCopy();
var_dump( $copyArr );
?>
|
Output:
array(8) {
[0]=>
string(1) "G"
[1]=>
string(1) "e"
[2]=>
string(1) "e"
[3]=>
string(1) "k"
[4]=>
string(1) "s"
[5]=>
string(1) "f"
[6]=>
string(1) "o"
[7]=>
string(1) "r"
}
Program 2:
<?php
$arrItr = new ArrayIterator(
array ( "Geeks" , "for" , "Geeks" )
);
$arrItr ->append( "Computer" );
$arrItr ->append( "Science" );
$arrItr ->append( "Portal" );
$copyArr = $arrItr ->getArrayCopy();
var_dump( $copyArr );
?>
|
Output:
array(6) {
[0]=>
string(5) "Geeks"
[1]=>
string(3) "for"
[2]=>
string(5) "Geeks"
[3]=>
string(8) "Computer"
[4]=>
string(7) "Science"
[5]=>
string(6) "Portal"
}
Reference: https://www.php.net/manual/en/arrayiterator.getarraycopy.php
Share your thoughts in the comments
Please Login to comment...