Ds \ Map::union()函数是PHP中的内置函数,用于创建包含两个映射的并集的新映射。
用法:
Ds\Map Ds\Map::union( $map )
参数:该函数接受单个参数$map,该参数用于保存实例的其他映射以与当前实例结合。
返回值:它返回一个包含两个映射的并集的映射。
以下示例程序旨在说明PHP中的Ds \ Map::union()函数:
程序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 Union of two map
echo("Union of both map is:\n");
print_r($a->union($b));
?>
输出:
Union of both map is:
Ds\Map Object
(
[0] => Ds\Pair Object
(
[key] => a
[value] => 2
)
[1] => Ds\Pair Object
(
[key] => b
[value] => 3
)
[2] => Ds\Pair Object
(
[key] => c
[value] => 3
)
[3] => Ds\Pair Object
(
[key] => d
[value] => 6
)
)
程序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 union of two map
echo("Union of both map is:\n");
print_r($a->union($b));
?>
输出:
Union of both map is:
Ds\Map Object
(
[0] => Ds\Pair Object
(
[key] => a
[value] => Geeks
)
[1] => Ds\Pair Object
(
[key] => b
[value] => Computer
)
[2] => Ds\Pair Object
(
[key] => c
[value] => Geeks
)
[3] => Ds\Pair Object
(
[key] => e
[value] => Science
)
[4] => Ds\Pair Object
(
[key] => f
[value] => Portal
)
)
参考: https://www.php.net/manual/en/ds-map.union.php
相关用法
- PHP Ds\Set union()用法及代码示例
- underscore.js _.union()用法及代码示例
- PHP Ds\Map sum()用法及代码示例
- PHP Ds\Set xor()用法及代码示例
- PHP key()用法及代码示例
- PHP pos()用法及代码示例
- PHP max( )用法及代码示例
- PHP Ds\Set first()用法及代码示例
- p5.js str()用法及代码示例
- PHP min( )用法及代码示例
注:本文由纯净天空筛选整理自R_Raj大神的英文原创作品 PHP | Ds\Map union() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
