Open In App

PHP Ds\Map toArray() Function

Last Updated : 21 Aug, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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 function does not accepts any parameter.

Return value: The function returns an associative array containing all of the elements of the specified Map instance.

Below programs illustrate the Ds\Map::toArray() function in PHP:

Program 1:




<?php
// PHP program to illustrate toArray() function
  
$map = new \Ds\Map([1 => 10, 2 => 20, 3 => 30]);
  
print_r($map->toArray());
  
?>


Output:

Array
(
    [1] => 10
    [2] => 20
    [3] => 30
)

Program 2:




<?php
// PHP program to illustrate toArray() function
  
$map = new \Ds\Map(["first" => "Geeks", "second" => "for"
            "third" => "Geeks"]);
  
print_r($map->toArray());
  
?>


Output:

Array
(
    [first] => Geeks
    [second] => for
    [third] => Geeks
)

Reference: http://php.net/manual/en/ds-map.toarray.php


Similar Reads

PHP | Ds\Collection toArray() Function
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 publ
1 min read
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 eleme
2 min read
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 contain
2 min read
PHP | Ds\Stack 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 array generated from the Stack. Below programs il
2 min read
PHP Ds\PriorityQueue toArray() Function
The Ds\PriorityQueue::toArray() Function in PHP is used to convert a PriorityQueue into an associative array in PHP. The values of the PriorityQueue are assigned to the array in order of decreasing priority. Syntax: array public Ds\PriorityQueue::toArray ( void ) Parameters: This function does not accepts any parameters. Return Value: This function
1 min read
PHP Ds\Queue 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 parameters. Return Value: This function converts the
1 min read
PHP Ds\Set 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::toArray ( void ) Parameter: This function does not acce
1 min read
PHP SplFixedArray toArray() Function
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:
1 min read
PHP | Ds\Pair 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 ) Parameters: This function does not accept any param
1 min read
PHP | Ds\Map map() Function
The Ds\Map::map() function of the Map class in PHP is used to apply a callback function to a Map object. This returns the result of applying the callback function to each value present on the map. The function does not update the values in the original map, instead, it just returns the result of the updates without affecting the original values. Sy
2 min read