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 Value: This function returns the array which contains all the elements of the Deque in the same order.
Below programs illustrate the Ds\Deque::toArray() function in PHP:
Program 1:
<?php // Declare a deque $deck = new \Ds\Deque([5, 6, 3, 2, 7, 1]); echo("Elements of Deque\n"); // Display the Deque elements print_r($deck); echo("Array elements\n"); // Use toArray() function to // convert Deque into array print_r($deck->toArray()); ?> |
Elements of Deque
Ds\Deque Object
(
[0] => 5
[1] => 6
[2] => 3
[3] => 2
[4] => 7
[5] => 1
)
Array elements
Array
(
[0] => 5
[1] => 6
[2] => 3
[3] => 2
[4] => 7
[5] => 1
)
Program 2:
<?php // Declare a deque $deck = new \Ds\Deque(["geeks", "for", "geeks", "data structures"]); echo("Elements of Deque\n"); // Display the Deque elements var_dump($deck); echo("Array elements\n"); // Use toArray() function to // convert Deque into array var_dump($deck->toArray()); ?> |
Elements of Deque
object(Ds\Deque)#1 (4) {
[0]=>
string(5) "geeks"
[1]=>
string(3) "for"
[2]=>
string(5) "geeks"
[3]=>
string(15) "data structures"
}
Array elements
array(4) {
[0]=>
string(5) "geeks"
[1]=>
string(3) "for"
[2]=>
string(5) "geeks"
[3]=>
string(15) "data structures"
}
Reference: http://php.net/manual/en/ds-deque.toarray.php
Recommended Posts:
- PHP Ds\Map toArray() Function
- PHP Ds\Set toArray() Function
- PHP | Ds\Pair toArray() Function
- PHP | Ds\Collection toArray() Function
- PHP | Ds\Stack toArray() Function
- PHP | SplFixedArray toArray() Function
- PHP Ds\PriorityQueue toArray() Function
- PHP | Ds\Vector toArray() Function
- PHP Ds\Queue toArray() Function
- jQuery | Misc toArray() Method
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- PHP | min( ) Function
- PHP | Ds\Map put() 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.



