PHP | Ds\Vector copy() Function
The Ds\Vector::copy() function is an inbuilt function in PHP which is used to create a copy of given vector.
Syntax:
Ds\Vector public Ds\Vector::copy( void )
Parameters: This function does not accept any parameter.
Return Value: This function returns a shallow copy of the vector.
Below programs illustrate the Ds\Vector::copy() function in PHP:
Program 1:
<?php // Create a vector array $arr1 = new \Ds\Vector([1, 2, 3, 5]); // Use copy() function to copy // the vector array $arr2 = $arr1->copy(); echo("Original Array \n"); // Display the original array print_r($arr1); echo("Copied Array \n"); // Display the copied array print_r($arr2); ?> |
Output:
Original Array
Ds\Vector Object
(
[0] => 1
[1] => 2
[2] => 3
[3] => 5
)
Copied Array
Ds\Vector Object
(
[0] => 1
[1] => 2
[2] => 3
[3] => 5
)
Program 2:
<?php // Create a vector array $arr1 = new \Ds\Vector(["geeks", "for", "geeks"]); // Use copy() function to copy // the vector array $arr2 = $arr1->copy(); echo("Original Array\n"); // Display the original array print_r($arr1); echo("Copied Array\n"); // Display the copied array print_r($arr2); ?> |
Output:
Original Array
Ds\Vector Object
(
[0] => geeks
[1] => for
[2] => geeks
)
Copied Array
Ds\Vector Object
(
[0] => geeks
[1] => for
[2] => geeks
)
Reference: http://php.net/manual/en/ds-vector.copy.php
Recommended Posts:
- PHP | Ds\Set copy() Function
- PHP Ds\Map copy() Function
- PHP | copy( ) Function
- PHP Ds\PriorityQueue copy() Function
- PHP Ds\Queue copy() Function
- PHP | Ds\Collection copy() Function
- PHP | Ds\Deque copy() Function
- PHP | Ds\Pair copy() Function
- PHP | Ds\Stack copy() Function
- How to create a copy of an object in PHP?
- How to copy the content of a div into another div using jQuery ?
- AngularJS | ng-copy Directive
- How to copy a file from one directory to another using PHP ?
- How to copy the text to the clipboard in JavaScript?
- Copy the entire contents of a directory to another directory in PHP
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.




