PHP | Ds\Map merge()函数
Ds\Map::merge()函数是PHP中的一个内置函数,用于返回添加所有给定关联的结果。
句法:
Ds\Map public Ds\Map::merge( $values )
参数:此函数接受单个参数$values ,其中包含可遍历的对象或数组。
返回值:此函数返回给定可遍历对象或数组的所有键与其对应值的关联,并结合当前实例。
下面的程序说明了PHP中的Ds\Map::merge()函数:
方案一:
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)
?>
输出:
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
)
)
方案二:
"Geeks",
"2" => "for", "3" => "Geeks"]);
// Merge the map element and display it
print_r($map->merge(["a" => "Computer",
"b" => "Science", "c" => "Portal"]));
?>
输出:
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
)
)
参考: https://www. PHP.net/manual/en/ds-map.merge。 PHP