Ds \ Vector::copy()函數是PHP中的一個內置函數,用於創建給定向量的副本。
用法:
Ds\Vector public Ds\Vector::copy( void )
參數:該函數不接受任何參數。
返回值:此函數返回向量的淺拷貝。
以下示例程序旨在說明PHP中的Ds \ Vector::copy()函數:
程序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);
?> 輸出:
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
)
程序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);
?>輸出:
Original Array
Ds\Vector Object
(
[0] => geeks
[1] => for
[2] => geeks
)
Copied Array
Ds\Vector Object
(
[0] => geeks
[1] => for
[2] => geeks
)
參考: http://php.net/manual/en/ds-vector.copy.php
相關用法
- PHP copy( )用法及代碼示例
- PHP Ds\Set copy()用法及代碼示例
- PHP Ds\Map copy()用法及代碼示例
- PHP Ds\Queue copy()用法及代碼示例
- PHP Ds\Collection copy()用法及代碼示例
- PHP Ds\Deque copy()用法及代碼示例
- PHP Ds\PriorityQueue copy()用法及代碼示例
- PHP Ds\Stack copy()用法及代碼示例
- PHP Ds\Pair copy()用法及代碼示例
- AngularJS ng-copy用法及代碼示例
- Node.js Buffer.copy()用法及代碼示例
注:本文由純淨天空篩選整理自barykrg大神的英文原創作品 PHP | Ds\Vector copy() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
