PHP | Ds\Pair copy() Function

The Ds\Pair::copy() function is an inbuilt function in PHP which is used to return a copy of Pair elements.

Syntax:

Ds\Pair Ds\Pair::copy( void )

Parameters: This function does not accept any parameters.



Return Value: This function returns a shallow copy of the pair element.

Below programs illustrate the Ds\Pair::copy() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
  
// Create new Pair
$pair = new \Ds\Pair("G", "GeeksforGeeks"); 
  
// Display the pair element 
print_r($pair); 
  
// Use copy() function 
$pair->copy(); 
  
echo "Copied pair elements:\n";
  
// Display the pair element 
print_r($pair); 
  
?> 

chevron_right


Output:

Ds\Pair Object
(
    [key] => G
    [value] => GeeksforGeeks
)
Copied pair elements:
Ds\Pair Object
(
    [key] => G
    [value] => GeeksforGeeks
)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
  
// Create new Pair
$pair = new \Ds\Pair(["G", "GeeksforGeeks"], [1, 2]); 
  
// Display the pair element 
var_dump($pair); 
  
// Use copy() function 
$pair->copy(); 
  
echo "Copied pair elements:\n";
  
// Display the pair element 
var_dump($pair); 
  
?> 

chevron_right


Output:

object(Ds\Pair)#1 (2) {
  ["key"]=>
  array(2) {
    [0]=>
    string(1) "G"
    [1]=>
    string(13) "GeeksforGeeks"
  }
  ["value"]=>
  array(2) {
    [0]=>
    int(1)
    [1]=>
    int(2)
  }
}
Copied pair elements:
object(Ds\Pair)#1 (2) {
  ["key"]=>
  array(2) {
    [0]=>
    string(1) "G"
    [1]=>
    string(13) "GeeksforGeeks"
  }
  ["value"]=>
  array(2) {
    [0]=>
    int(1)
    [1]=>
    int(2)
  }
}

Reference: https://www.php.net/manual/en/ds-pair.copy.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.