Related Articles

Related Articles

PHP | Ds\Vector copy() Function
  • Last Updated : 22 Aug, 2019

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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);
  
?> 

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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);
  
?>

chevron_right


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




My Personal Notes arrow_drop_up
Recommended Articles
Page :