PHP | Ds\Collection toArray() Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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 <?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 <?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: https://www.php.net/manual/en/ds-collection.toarray.php Comment More infoAdvertise with us Next Article PHP | Ds\Deque toArray() Function V vijay_raj Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DS\Collection Similar Reads PHP | Ds\Collection copy() Function The Ds\Collection::copy() function is an inbuilt function in PHP which is used to returns the copy of collection element. Syntax: Ds\Collection::copy ( void ) : Ds\Collection Parameters: This function does not accept any parameter. Return Value: It returns the copy of collection element. Below progr 2 min read PHP | Ds\Collection copy() Function The Ds\Collection::copy() function is an inbuilt function in PHP which is used to returns the copy of collection element. Syntax: Ds\Collection::copy ( void ) : Ds\Collection Parameters: This function does not accept any parameter. Return Value: It returns the copy of collection element. Below progr 2 min read PHP | Ds\Deque toArray() Function The Ds\Deque::toArray() function is an inbuilt function in PHP which is used to convert a Deque into an array. The elements of the array will be in the same order as they are in Deque. Syntax: public Ds\Deque::toArray( void ) : array Parameters: This function does not accept any parameter. Return Va 2 min read PHP | Ds\Deque toArray() Function The Ds\Deque::toArray() function is an inbuilt function in PHP which is used to convert a Deque into an array. The elements of the array will be in the same order as they are in Deque. Syntax: public Ds\Deque::toArray( void ) : array Parameters: This function does not accept any parameter. Return Va 2 min read PHP | Ds\Collection clear() Function The Ds\Collection::clear() function is an inbuilt function in PHP which is used to remove all values from the collection. Syntax: Ds\Collection::clear( void ) Parameters: This function does not accepts any parameters. Return Value: This function does not return any value. Below programs illustrate t 1 min read PHP | Ds\Collection clear() Function The Ds\Collection::clear() function is an inbuilt function in PHP which is used to remove all values from the collection. Syntax: Ds\Collection::clear( void ) Parameters: This function does not accepts any parameters. Return Value: This function does not return any value. Below programs illustrate t 1 min read Like