The SplFixedArray::toArray() function is an inbuilt function in PHP which is used to get a PHP array from the fixed array.
Syntax:
array SplFixedArray::toArray()
Parameters: This function does not accept any parameter.
Return Value: This function returns a PHP array.
Below programs illustrate the SplFixedArray::toArray() function in PHP:
Program 1:
<?php // Create a fixed size array $gfg = new SplFixedArray(3); $gfg[0] = 1; $gfg[1] = 5; $gfg[2] = 10; var_dump($gfg->toArray()); ?> |
array(3) {
[0]=>
int(1)
[1]=>
int(5)
[2]=>
int(10)
}
Program 2:
<?php // Create some fixed size array $gfg = new SplFixedArray(3); $gfg1 = new SplFixedArray(6); $gfg1[0] = 1; $gfg1[1] = 5; $gfg1[2] = 10; $gfg2 = new SplFixedArray(5); $gfg2[0] = 1; $gfg2[1] = 5; $gfg2[2] = 10; $gfg2[3] = 10; $gfg2[4] = 20; // Print result var_dump($gfg->toArray()); var_dump($gfg1->toArray()); var_dump($gfg2->toArray()); ?> |
array(3) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
}
array(6) {
[0]=>
int(1)
[1]=>
int(5)
[2]=>
int(10)
[3]=>
NULL
[4]=>
NULL
[5]=>
NULL
}
array(5) {
[0]=>
int(1)
[1]=>
int(5)
[2]=>
int(10)
[3]=>
int(10)
[4]=>
int(20)
}
Reference: https://www.php.net/manual/en/splfixedarray.toarray.php
Recommended Posts:
- PHP | SplFixedArray count() Function
- PHP | SplFixedArray current() Function
- PHP | SplFixedArray __construct() Function
- PHP | SplFixedArray next() Function
- PHP | SplFixedArray key() Function
- PHP | SplFixedArray getSize() Function
- PHP | SplFixedArray valid() Function
- PHP | SplFixedArray setSize() Function
- PHP | SplFixedArray rewind() Function
- PHP | SplFixedArray offsetUnset () Function
- PHP | SplFixedArray offsetGet() Function
- PHP | SplFixedArray offsetExists() Function
- PHP | Ds\Collection toArray() Function
- PHP | Ds\Vector toArray() Function
- PHP Ds\Map toArray() Function
- PHP | Ds\Deque toArray() Function
- PHP | Ds\Stack toArray() Function
- PHP Ds\PriorityQueue toArray() Function
- PHP Ds\Queue toArray() Function
- PHP Ds\Set toArray() 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.

