The Ds\Collection::toArray() function is an inbuilt function in PHP which is used to converts the collections into array.
Syntax:
public Ds\Collection::toArray( void ) : array
Parameters: This function does not accepts any parameters.
Return Value: This function returns an array containing all collection elements.
Below programs illustrate the public Ds\Collection::toArray() function in PHP:
Example 1:
<?php
$collection = new \Ds\Vector([10, 15, 21, 13, 16, 18]);
var_dump( $collection ->toArray());
?>
|
Output:
array(6) {
[0] => int(10)
[1] => int(15)
[2] => int(21)
[3] => int(13)
[4] => int(16)
[5] => int(18)
}
Example 2:
<?php
$collection = new \Ds\Vector([10, 15, 21, 13, 16, 18]);
print_r( $collection );
print_r( $collection ->toArray());
?>
|
Output:
Ds\Vector Object
(
[0] => 10
[1] => 15
[2] => 21
[3] => 13
[4] => 16
[5] => 18
)
Array
(
[0] => 10
[1] => 15
[2] => 21
[3] => 13
[4] => 16
[5] => 18
)
Reference: http://php.net/manual/en/ds-collection.toarray.php
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
23 Jan, 2019
Like Article
Save Article