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

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(["neveropen", "for", "neveropen"]);
  
// 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] => neveropen
    [1] => for
    [2] => neveropen
)
Copied Array
Ds\Vector Object
(
    [0] => neveropen
    [1] => for
    [2] => neveropen
)

Reference: http://php.net/manual/en/ds-vector.copy.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6899 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