Related Articles

Related Articles

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
   
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
    array('G', 'e', 'e', 'k', 's', 'f', 'o', 'r')
);
  
// Create a copy of array
$copyArr = $arrItr->getArrayCopy();
  
// Display the array iterator element
var_dump($copyArr);
   
?>

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
   
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
    array("Geeks", "for", "Geeks")
);
   
// Append the element into array
$arrItr->append("Computer");
$arrItr->append("Science");
$arrItr->append("Portal");
  
// Create copy of array iterator
$copyArr = $arrItr->getArrayCopy();
  
// Display the array element 
var_dump($copyArr);
  
?>

chevron_right


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




My Personal Notes arrow_drop_up
Recommended Articles
Page :