PHP | Ds\Vector toArray() Function Last Updated : 24 Oct, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report The Ds\Vector::toArray() function is an inbuilt function in PHP which is used to convert the vector into an array. All the elements of the vector are copied to the array.Syntax: array public Ds\Vector::toArray( void ) Parameters: This function does not accepts any parameters.Return Value: This function returns the array which contains all the elements of the vector.Below programs illustrate the Ds\Vector::toArray() function in PHP:Program 1: PHP <?php // Declare new Vector $vect = new \Ds\Vector([3, 6, 1, 2, 9, 7]); echo("Original vector\n"); // Display the vector elements var_dump($vect); echo("\nArray elements\n"); // Use toArray() function to convert // vector to array and display it var_dump($vect->toArray()); ?> Output: Original vector object(Ds\Vector)#1 (6) { [0]=> int(3) [1]=> int(6) [2]=> int(1) [3]=> int(2) [4]=> int(9) [5]=> int(7) } Array elements array(6) { [0]=> int(3) [1]=> int(6) [2]=> int(1) [3]=> int(2) [4]=> int(9) [5]=> int(7) } Program 2: PHP <?php // Declare new Vector $vect = new \Ds\Vector(["geeks", "for", "geeks"]); echo("Original vector\n"); // Display the vector elements var_dump($vect); echo("\nArray elements\n"); // Use toArray() function to convert // vector to array and display it var_dump($vect->toArray()); ?> Output: Original vector object(Ds\Vector)#1 (3) { [0]=> string(5) "geeks" [1]=> string(3) "for" [2]=> string(5) "geeks" } Array elements array(3) { [0]=> string(5) "geeks" [1]=> string(3) "for" [2]=> string(5) "geeks" } Reference: http://php.net/manual/en/ds-vector.toarray.php Comment More infoAdvertise with us Next Article PHP | Ds\Vector toArray() Function B barykrg Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_vector Similar Reads PHP DsMap toArray() Function The Ds\Map::toArray() function in PHP is used to get an array generated by converting the Map instance into an Array. The resulting array is an associative array with elements as in same order as that of the specified Map instance. Syntax: array public Ds\Map::toArray ( void ) Parameter: This functi 1 min read PHP DsSet toArray() Function The Ds\Set::toArray() function of Ds\Set class in PHP is an inbuilt function which is used to convert the Set into an associative array. This does not modify the actual Set. This method returns an array with values of the Set without changing the order of elements. Syntax: array public Ds\Set::toArr 1 min read PHP | DsPair toArray() Function The Ds\Pair::toArray() function is an inbuilt function in PHP which is used to convert the Pair element into an associative array. This function does not modify the actual Pair. This method returns an array whose values without changing the order of elements. Syntax: array Ds\Pair::toArray( void ) P 1 min read PHP | DsStack toArray() Function The Ds\Stack::toArray() function of PHP is used to convert the stack to an array and returns the converted array. This function does not modify the actual Stack. Syntax: void public Ds\Stack::toArray () Parameters: This function does not accept any parameters. Return Value: This function returns the 2 min read PHP | DsDeque 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 Like