PHP | Ds\Pair copy() Function
Last Updated :
20 Mar, 2023
The Ds\Pair::copy() function is an inbuilt function in PHP which is used to return a copy of Pair elements. Syntax:
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:
php
<?php
$pair = new \Ds\Pair("G", "GeeksforGeeks");
print_r( $pair );
$pair -> copy ();
echo "Copied pair elements:\n";
print_r( $pair );
?>
|
Output:
Ds\Pair Object
(
[key] => G
[value] => GeeksforGeeks
)
Copied pair elements:
Ds\Pair Object
(
[key] => G
[value] => GeeksforGeeks
)
Program 2:
php
<?php
$pair = new \Ds\Pair(["G", "GeeksforGeeks"], [1, 2]);
var_dump( $pair );
$pair -> copy ();
echo "Copied pair elements:\n";
var_dump( $pair );
?>
|
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...