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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
