Open In App

PHP | Ds\Map xor() Function

Improve
Improve
Like Article
Like
Save
Share
Report

The Ds\Map::xor() function is an inbuilt function in PHP which is used to create a new map which contains the value either in the first map or second map but not both.

Syntax:

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

Parameter: This parameter holds the other map of values.

Return value: It is used to return a map which contains the xor of the current map with another map.

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

Program 1:




<?php 
  
// Declare a new map
$a = new \Ds\Map(["a" => 1, "b" => 3, "c" => 5]); 
  
// Declare another new map
$b = new \Ds\Map(["a" => 2, "c" => 3, "d" => 6]); 
  
// Print the xor of two map
echo("xor of both map is: \n"); 
  
print_r($a->xor($b));
  
?>


Output:

xor of both map is: 
Ds\Map Object
(
    [0] => Ds\Pair Object
        (
            [key] => b
            [value] => 3
        )

    [1] => Ds\Pair Object
        (
            [key] => d
            [value] => 6
        )

)

Program 2:




<?php 
  
// Declare a new map
$a = new \Ds\Map(["a" => "Geeks", "b" => "for"
                                          "c" => "Geeks"]); 
  
// Declare another new map
$b = new \Ds\Map(["b" => "Computer", "e" => "Science",
                                         "f" => "Portal"]); 
  
// Print the xor of two map
echo("xor of both map is: \n"); 
  
print_r($a->xor($b));
  
?>


Output:

xor of both map is: 
Ds\Map Object
(
    [0] => Ds\Pair Object
        (
            [key] => a
            [value] => Geeks
        )

    [1] => Ds\Pair Object
        (
            [key] => c
            [value] => Geeks
        )

    [2] => Ds\Pair Object
        (
            [key] => e
            [value] => Science
        )

    [3] => Ds\Pair Object
        (
            [key] => f
            [value] => Portal
        )

)

Reference: https://www.php.net/manual/en/ds-map.xor.php



Last Updated : 21 Aug, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads