Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

PHP - Ds Deque::copy() Function



The PHP Ds\Deque::copy() function is used to retrieve a shallow copy of the current deque. A shallow copy of a collection (or deque) is a copy where the properties share the same references as those of the source object from which the copy was made.

You can invoke this function on any collection such as a set, stack, deque, etc.

Syntax

Following is the syntax of the PHP Ds\Deque::copy() function −

public Ds\Deque::copy(): Ds\Deque

Parameters

This function does not accept any parameter.

Return value

This function returns a shallow copy of the current deque.

Example 1

The following is the basic example of the PHP Ds\Deque::copy() function −

<?php
   $deque = new \Ds\Deque([10, 20, 30, 40, 50]);
   echo "The original deque: \n";
   print_r($deque);
   echo "The shallow copy of a deque: \n";
   print_r($deque->copy());
?>

Output

The above program displays the following output −

The original deque:
Ds\Deque Object
(
    [0] => 10
    [1] => 20
    [2] => 30
    [3] => 40
    [4] => 50
)
The shallow copy of a deque:
Ds\Deque Object
(
    [0] => 10
    [1] => 20
    [2] => 30
    [3] => 40
    [4] => 50
)

Example 2

Following is another example of the PHP Ds\Deque::copy() function. We use this function to retrieve a shallow copy of this deque (["Tutorials", "Point", "India"]) −

<?php
   $deque = new \Ds\Deque(["Tutorials", "Point", "India"]);
   echo "The original deque: \n";
   print_r($deque);
   echo "The shallow copy of a deque: \n";
   print_r($deque->copy());
?>

Output

After executing the above program, it will generate the following output −

The original deque:
Ds\Deque Object
(
    [0] => Tutorials
    [1] => Point
    [2] => India
)
The shallow copy of a deque:
Ds\Deque Object
(
    [0] => Tutorials
    [1] => Point
    [2] => India
)
php_function_reference.htm
Advertisements