+

PHP Ds / Collection copy () function

Syntax:
DsCollection::copy (void): DsCollection 
Parameters:this function takes no parameters .Return value:returns a copy of the collection item.The following programs illustrate the Ds / Collection::copy() function in PHP:Example 1:  
// Create collection $collection = new DsVector ([10, 15, 21, 13, 16, 18]);  
// Show collection item print_r ( $collection );  
// Use the copy() function to remove elements $collection -> copy ();  
// Show collection item print_r ( $collection );  
?>
Output:
DsVector Object ([0] = > 10 [1] = > 15 [2] = > 21 [3] = > 13 [4] = > 16 [5] = > 18) DsVector Object ([0] = > 10 [1] = > 15 [2] = > 21 [3] = > 13 [4] = > 16 [5] = > 18) 
Example 2:  
// Create collection $collection = new DsVector ([10, 15, 21, 13, 16, 18]) ;  
// Show collection item print_r ( $collection );  
// Use the copy() function to remove elements $collection -> copy ();  
// retrieve an item from the collection $collection -> pop();  
// Show collection item print_r ( $collection );  
?>
Output:
DsVector Object ([0] = > 10 [1] = > 15 [2] = > 21 [3] = > 13 [4] = > 16 [5] = > 18) DsVector Object ([0] = > 10 [1] = > 15 [2] = > 21 [3] = > 13 [4] = > 16) 
Link : http://php.net/manual/en/ds-collection.copy.php
Get Solution for free from DataCamp guru