PHP | Ds\Vector toArray() Function
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 // Declare new Vector $vect = new \Ds\Vector([3, 6, 1, 2, 9, 7]); echo("Original vector\n"); // Desplay 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 // Declare new Vector $vect = new \Ds\Vector(["geeks", "for", "geeks"]); echo("Original vector\n"); // Desplay 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
Recommended Posts:
- PHP Ds\Map toArray() Function
- PHP Ds\Set toArray() Function
- PHP | Ds\Stack toArray() Function
- PHP Ds\PriorityQueue toArray() Function
- PHP | Ds\Pair toArray() Function
- PHP | Ds\Collection toArray() Function
- PHP | SplFixedArray toArray() Function
- PHP Ds\Queue toArray() Function
- PHP | Ds\Deque 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 ?
- PHP | dir() Function
- PHP | min( ) Function
- D3.js | d3.rgb() 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.



