Friday, June 19, 2026
HomeLanguagesPHP | DsPair copy() Function

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::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
 
// Create new Pair
$pair = new \Ds\Pair("G", "neveropen");
 
// Display the pair element
print_r($pair);
 
// Use copy() function
$pair->copy();
 
echo "Copied pair elements:\n";
 
// Display the pair element
print_r($pair);
 
?>


Output:

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

Program 2: 

php




<?php
 
// Create new Pair
$pair = new \Ds\Pair(["G", "neveropen"], [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);
 
?>


Output:

object(Ds\Pair)#1 (2) {
  ["key"]=>
  array(2) {
    [0]=>
    string(1) "G"
    [1]=>
    string(13) "neveropen"
  }
  ["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) "neveropen"
  }
  ["value"]=>
  array(2) {
    [0]=>
    int(1)
    [1]=>
    int(2)
  }
}

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

RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6898 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6965 POSTS0 COMMENTS