PHP | Ds\Map put() Function Last Updated : 21 Aug, 2019 Comments Improve Suggest changes Like Article Like Report The Ds\Map::put() function is an inbuilt function in PHP, which is used to associates a key with a value. Syntax: void public Ds\Map::put( $key, $value ) Parameter: This function accepts two parameters as mentioned above and described below: $key: It is used to hold the key to associate the value. $value: It is used to hold the value of key. Return value: This function does not return any value. Below programs illustrate the Ds\Map::put() function in PHP: Program 1: php <?php // Declare a new map $map = new \Ds\Map(); $map->put("a", "Geeks"); $map->put("b", "for"); $map->put("c", "Geeks"); // Display output print_r($map); // Declare a new map $map = new \Ds\Map(); $map->put("a", "Computer"); $map->put("b", "Science"); $map->put("c", "Portal"); // Display output print_r($map); ?> Output: Ds\Map Object ( [0] => Ds\Pair Object ( [key] => a [value] => Geeks ) [1] => Ds\Pair Object ( [key] => b [value] => for ) [2] => Ds\Pair Object ( [key] => c [value] => Geeks ) ) Ds\Map Object ( [0] => Ds\Pair Object ( [key] => a [value] => Computer ) [1] => Ds\Pair Object ( [key] => b [value] => Science ) [2] => Ds\Pair Object ( [key] => c [value] => Portal ) ) Program 2: php <?php // Declare a new map $map = new \Ds\Map(); $map->put("Geeks1", "computer"); $map->put("Geeks2", "science"); $map->put("Geeks3", 5); $map->put("Geeks3", 20); // Display result var_dump($map); ?> Output: object(Ds\Map)#1 (3) { [0]=> object(Ds\Pair)#2 (2) { ["key"]=> string(6) "Geeks1" ["value"]=> string(8) "computer" } [1]=> object(Ds\Pair)#3 (2) { ["key"]=> string(6) "Geeks2" ["value"]=> string(7) "science" } [2]=> object(Ds\Pair)#4 (2) { ["key"]=> string(6) "Geeks3" ["value"]=> int(20) } } Reference: https://www.php.net/manual/en/ds-map.put.php Comment More infoAdvertise with us Next Article PHP | Ds\Map put() Function R R_Raj Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_map Similar Reads PHP | DsDeque map() Function The Ds\Deque::map() function is an inbuilt function in PHP which is used to return the Deque with each element modified on the basis of operation performed as per the callback function. Syntax: public Ds\Deque::map( $callback ) : Ds\Deque Parameters: This function accepts single parameter $callback 2 min read PHP | DsVector map() Function The Ds\Vector::map() function is an inbuilt function in PHP which is used to return the result of a callback after applying to each value in the vector. Syntax: Ds\Vector public Ds\Vector::map( $callback ) Parameters: This function accepts single parameter $callback which is to be applied to each ve 2 min read PHP | DsSequence map() Function The Ds\Sequence::map() function is an inbuilt function in PHP which returns the result after applying callback function to each value. Syntax: Ds\Sequence abstract public Ds\Sequence::map( $callback ) Parameter: This function accepts single parameter $callback. The callback apply on each value of se 1 min read PHP DsMap sum() Function The Ds\Map::sum() function of PHP is used to get the sum of all of the values present in the Map instance. Syntax: number public Ds\Map::sum ( void ) Parameters: This function does not accepts any parameter. Return value: This function returns the sum of all of the values present in the Map instance 1 min read PHP | array_map() Function The array_map() is an inbuilt function in PHP and it helps to modify all elements one or more arrays according to some user-defined condition in an easy manner. It basically, sends each of the elements of an array to a user-defined function and returns an array with new values as modified by that fu 2 min read PHP | DsStack push() Function The Ds\Stack::push() function of PHP is used to add elements at the end of the stack. That it is used to push elements on to a stack. The elements being pushed can be of mixed data types. Syntax: void public Ds\Stack::push ($values) Parameter: This function accepts a single parameter $values which i 1 min read PHP | DsDeque push() Function The Ds\Deque::push() function is an inbuilt function in PHP which is used to add the elements to the Deque by appending an element at the end of the Deque. Syntax: public Ds\Deque::push( $values ) : void Parameters: This function accepts single parameter $values which holds the elements to be added 2 min read PHP DsQueue push() Function The Ds\Queue::push() Function in PHP is used to push or insert values in a PriorityQueue instance. This function can also insert a list of values directly to the Queue. Syntax: void public Ds\Queue::push($value1, $value2, .... $valueN) Parameters: This function accepts a list of values separated by 1 min read PHP | DsMap sort() Function The Ds\Map::sort() function of DS\Map class in PHP is used to in-place sort the elements of a specified Map instance according to the values. By default, the Map is sorted according to the increasing order of the values. Syntax: Ds\Pair public Ds\Map::sort ( int $position ) Parameter: This function 2 min read PHP | DsSet last() Function The Ds\Set::last() function is an inbuilt function in PHP which is used to return the last element from the Set instance. Syntax: void public Ds\Set::last( void ) Parameter: This function does not accept any parameter. Return Value: This function returns the last value of the Set. Below programs ill 1 min read Like