PHP | Ds\Stack toArray() Function Last Updated : 19 Jan, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 array generated from the Stack. Below programs illustrate the Ds\Stack::toArray() function: Program 1: PHP <?php // PHP program to illustrate the // Ds\stack::toArray() function // Create a Stack instance $stack = new \Ds\Stack(); // Pushing elements to Stack $stack->push("Welcome"); $stack->push("to"); $stack->push("GfG"); // Print the converted array print_r($stack->toArray()); // Print the Stack print_r($stack); ?> Output: Array ( [0] => GfG [1] => to [2] => Welcome ) Ds\Stack Object ( [0] => GfG [1] => to [2] => Welcome ) Program 2: PHP <?php // PHP program to illustrate the // Ds\stack::toArray() function // Create a Stack instance $stack = new \Ds\Stack(); // Pushing Mixed value elements to Stack $stack->push("Welcome"); $stack->push("to"); $stack->push("GfG"); $stack->push(10); $stack->push(5.5); // Print the converted Array print_r($stack->toArray()); // Print the Stack print_r($stack); ?> Output: Array ( [0] => 5.5 [1] => 10 [2] => GfG [3] => to [4] => Welcome ) Ds\Stack Object ( [0] => 5.5 [1] => 10 [2] => GfG [3] => to [4] => Welcome ) Reference: http://php.net/manual/en/ds-stack.toarray.php Comment More infoAdvertise with us Next Article PHP | DsDeque toArray() Function G gopaldave Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_stack 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 PHP DsQueue toArray() Function The Ds\Queue::toArray() Function in PHP is used to convert a Queue into an associative array in PHP. The values of the Queue are assigned to the array in the same order as they are present in the Queue. Syntax: array public Ds\Queue::toArray ( void ) Parameters: This function does not accepts any pa 1 min read PHP | Ds\Stack toArray() Function min read Like