PHP | Ds\Collection toArray() Function
The Ds\Collection::toArray() function is an inbuilt function in PHP which is used to converts the collections into array.
Syntax:
public Ds\Collection::toArray( void ) : array
Parameters: This function does not accepts any parameters.
Return Value: This function returns an array containing all collection elements.
Below programs illustrate the public Ds\Collection::toArray() function in PHP:
Example 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()); ?> |
Output:
array(6) {
[0] => int(10)
[1] => int(15)
[2] => int(21)
[3] => int(13)
[4] => int(16)
[5] => int(18)
}
Example 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()); ?> |
Output:
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
)
Reference: http://php.net/manual/en/ds-collection.toarray.php
Recommended Posts:
- PHP Ds\Map toArray() Function
- PHP Ds\Set toArray() Function
- PHP | Ds\Pair toArray() Function
- PHP | Ds\Stack toArray() Function
- PHP Ds\PriorityQueue toArray() Function
- PHP | SplFixedArray toArray() Function
- PHP Ds\Queue toArray() Function
- PHP | Ds\Deque toArray() Function
- PHP | Ds\Vector toArray() Function
- jQuery | Misc toArray() Method
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- How to get the function name inside a function in PHP ?
- D3.js | d3.mean() function
- p5.js | nfs() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



