Home >Backend Development >PHP Problem >How to use Ds\Vector copy() function in PHP?
This article will introduce to you how to use the Ds\Vector copy() function in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
DsVector::copy() function is a built-in function in PHP that is used to create a copy of a given vector.
The syntax is as follows:
DsVector public DsVector::copy( void )
Parameters: This function does not accept any parameters.
Return value: This function returns a shallow copy of the vector.
The following program illustrates the usage of the DsVector::copy() function in PHP:
Program 1:
<?php // Create a vector array $arr1 = new DsVector([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 ); ?>
The output is as follows:
Original Array DsVector Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 5 ) Copied Array DsVector Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 5 )
Program 2:
<?php // Create a vector array $arr1 = new DsVector([ "geeks" , "for" , "geeks" ]); // Use copy() function to copy // the vector array $arr2 = $arr1 -> copy (); echo ( "Original Arrayn" ); // Display the original array print_r( $arr1 ); echo ( "Copied Arrayn" ); // Display the copied array print_r( $arr2 ); ?>
The output is as follows:
Original Array DsVector Object ( [0] => geeks [1] => for [2] => geeks ) Copied Array DsVector Object ( [0] => geeks [1] => for [2] => geeks )
Recommended learning: php video tutorial
The above is the detailed content of How to use DsVector copy() function in PHP?. For more information, please follow other related articles on the PHP Chinese website!