• PHP Video Tutorials

PHP - Ds Map union() Function



Ds\Map::union() function can create a new map using values from the current instance and another map.

Syntax

public Ds\Map Ds\Map::union( Ds\Map $map )

Ds\Map::union() function can return a new map containing all pairs of the current instance as well as another map.

Example 1

<?php  
   $map1 = new \Ds\Map(["a" => 1, "b" => 3, "c" => 5]);  
   $map2 = new \Ds\Map(["a" => 2, "c" => 3, "d" => 6]);  
  
   echo("The union of both map: \n");  
   print_r($map1->union($map2)); 
?>

Example 2

<?php  
   $map1 = new \Ds\Map(["a" => "Tutorials", "b" => "Point", "c" => "India"]);  
   $map2 = new \Ds\Map(["b" => "Tuotorix", "d" => "Madhapur", "e" => "Hyderabad"]);  
   
   echo("The union of both map: \n");  
   print_r($map1->union($map2)); 
?>
php_function_reference.htm
Advertisements