Ds \ Collection::toArray()函數是PHP中的內置函數,用於將集合轉換為數組。
用法:
public Ds\Collection::toArray( void ):array
參數:該函數不接受任何參數。
返回值:此函數返回包含所有集合元素的數組。
以下示例程序旨在說明PHP中的公共Ds \ Collection::toArray()函數:
範例1:
<?php
// Create a collection
$collection = new \Ds\Vector([10, 15, 21, 13, 16, 18]);
// Use toArray() function to convert
// collections to array
var_dump($collection->toArray());
?> 輸出:
array(6) {
[0] => int(10)
[1] => int(15)
[2] => int(21)
[3] => int(13)
[4] => int(16)
[5] => int(18)
}
範例2:
<?php
// Create a collection
$collection = new \Ds\Vector([10, 15, 21, 13, 16, 18]);
// Display the collection element
print_r($collection);
// Use toArray() function to convert
// collection into array and print it
print_r($collection->toArray());
?> 輸出:
Ds\Vector Object
(
[0] => 10
[1] => 15
[2] => 21
[3] => 13
[4] => 16
[5] => 18
)
Array
(
[0] => 10
[1] => 15
[2] => 21
[3] => 13
[4] => 16
[5] => 18
)
參考: http://php.net/manual/en/ds-collection.toarray.php
相關用法
- PHP Ds\Map toArray()用法及代碼示例
- PHP Ds\Set toArray()用法及代碼示例
- PHP SplFixedArray toArray()用法及代碼示例
- PHP Ds\Vector toArray()用法及代碼示例
- PHP Ds\Queue toArray()用法及代碼示例
- PHP Ds\PriorityQueue toArray()用法及代碼示例
- PHP Ds\Pair toArray()用法及代碼示例
- PHP Ds\Deque toArray()用法及代碼示例
- PHP Ds\Stack toArray()用法及代碼示例
- JQuery Misc toArray()用法及代碼示例
- PHP dir()用法及代碼示例
- p5.js nf()用法及代碼示例
注:本文由純淨天空篩選整理自Mahadev99大神的英文原創作品 PHP | Ds\Collection toArray() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
