Ds \ Collection::copy()函數是PHP中的一個內置函數,用於返回collection元素的副本。
用法:
Ds\Collection::copy ( void ):Ds\Collection
參數:該函數不接受任何參數。
返回值:它返回collection元素的副本。
以下示例程序旨在說明PHP中的Ds \ Collection::copy()函數:
範例1:
<?php
// Create a collection
$collection = new \Ds\Vector([10, 15, 21, 13, 16, 18]);
// Display the collection element
print_r($collection);
// Use copy() function to remove elements
$collection->copy();
// Display the collection element
print_r($collection);
?>輸出:
Ds\Vector Object (
[0] => 10
[1] => 15
[2] => 21
[3] => 13
[4] => 16
[5] => 18
)
Ds\Vector Object (
[0] => 10
[1] => 15
[2] => 21
[3] => 13
[4] => 16
[5] => 18
)
範例2:
<?php
// Create a collection
$collection = new \Ds\Vector([10, 15, 21, 13, 16, 18]);
// Display the collection element
print_r($collection);
// Use copy() function to remove elements
$collection->copy();
// Pop an element from collection
$collection->pop();
// Display the collection element
print_r($collection);
?>輸出:
Ds\Vector Object (
[0] => 10
[1] => 15
[2] => 21
[3] => 13
[4] => 16
[5] => 18
)
Ds\Vector Object (
[0] => 10
[1] => 15
[2] => 21
[3] => 13
[4] => 16
)
參考: http://php.net/manual/en/ds-collection.copy.php
相關用法
- PHP Ds\Set copy()用法及代碼示例
- PHP copy( )用法及代碼示例
- PHP Ds\Map copy()用法及代碼示例
- PHP Ds\PriorityQueue copy()用法及代碼示例
- PHP Ds\Queue copy()用法及代碼示例
- PHP Ds\Stack copy()用法及代碼示例
- PHP Ds\Vector copy()用法及代碼示例
- PHP Ds\Pair copy()用法及代碼示例
- PHP Ds\Deque copy()用法及代碼示例
- AngularJS ng-copy用法及代碼示例
- Node.js Buffer.copy()用法及代碼示例
注:本文由純淨天空篩選整理自Mahadev99大神的英文原創作品 PHP | Ds\Collection copy() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
