PHP | Ds\Map merge() Function Last Updated : 21 Aug, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The Ds\Map::merge() function is an inbuilt function in PHP which is used to return the result of adding all given associations. Syntax: Ds\Map public Ds\Map::merge( $values ) Parameter: This function accepts single parameter $values which holds the traversable object or an array. Return value: This function returns the associating all keys of a given traversable object or array with their corresponding values, combined with the current instance. Below programs illustrate the Ds\Map::merge() function in PHP: Program 1: php <?php // Create new map $map = new \Ds\Map(["a" => 12, "b" => 15, "c" => 18, "d" => 20]); // Merge the map element and display it print_r($map->merge(["a" => 1, "c" => 2, "f" => 3])); // Display the set element print_r($map) ?> Output: Ds\Map Object ( [0] => Ds\Pair Object ( [key] => a [value] => 1 ) [1] => Ds\Pair Object ( [key] => b [value] => 15 ) [2] => Ds\Pair Object ( [key] => c [value] => 2 ) [3] => Ds\Pair Object ( [key] => d [value] => 20 ) [4] => Ds\Pair Object ( [key] => f [value] => 3 ) ) Ds\Map Object ( [0] => Ds\Pair Object ( [key] => a [value] => 12 ) [1] => Ds\Pair Object ( [key] => b [value] => 15 ) [2] => Ds\Pair Object ( [key] => c [value] => 18 ) [3] => Ds\Pair Object ( [key] => d [value] => 20 ) ) Program 2: php <?php // Create new map $map = new \Ds\Map(["1" => "Geeks", "2" => "for", "3" => "Geeks"]); // Merge the map element and display it print_r($map->merge(["a" => "Computer", "b" => "Science", "c" => "Portal"])); ?> Output: Ds\Map Object ( [0] => Ds\Pair Object ( [key] => 1 [value] => Geeks ) [1] => Ds\Pair Object ( [key] => 2 [value] => for ) [2] => Ds\Pair Object ( [key] => 3 [value] => Geeks ) [3] => Ds\Pair Object ( [key] => a [value] => Computer ) [4] => Ds\Pair Object ( [key] => b [value] => Science ) [5] => Ds\Pair Object ( [key] => c [value] => Portal ) ) Reference: https://www.php.net/manual/en/ds-map.merge.php Comment More infoAdvertise with us Next Article PHP | Ds\Map merge() Function R R_Raj Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_map Similar Reads PHP | DsSet merge() Function The Ds\Set::merge() function is an inbuilt function in PHP which returns a set after adding all given values to the set. Syntax: Ds\Set public Ds\Set::merge ( mixed $values ) Parameters: This function accepts single parameter $values which holds the elements. Return Value: This function returns the 1 min read PHP | DsDeque merge() Function The Ds\Deque::merge() function is an inbuilt function in PHP which is used to return the merged Deque after merging all the elements of one Deque with another by adding all the values into a copy and returns that copy. Syntax: public Ds\Deque::merge( $values ) : Ds\Deque Parameters: This function ac 2 min read PHP | DsVector merge() Function The Ds\Vector::merge() function is an inbuilt function in PHP which is used to merge all the elements to the vector. Syntax: Ds\Vector public Ds\Vector::merge( $values ) Parameters: This function accepts a single parameter $values which is the traversable object or array.Return Value: This function 2 min read PHP | DsSequence merge() Function The Ds\Sequence::merge() function is an inbuilt function in PHP which returns a sequence after adding all given values to the sequence. Syntax: abstract public Ds\Sequence::merge( $values ) : Ds\Sequence Parameter: This function accepts single parameter $values which holds the elements. Return Value 1 min read 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 Like