牛牛在线工具

Ds\Map::putAll()

收录 8868 个 PHP 函数,含用途说明与用法示例。

Ds\Map::putAll()

将一个迭代器或关联数组中的键值对添加到当前的 Map 对象中

函数名称: Ds\Map::putAll() 适用版本: >= 1.0.0 用法: Ds\Map::putAll() 函数用于将一个迭代器或关联数组中的键值对添加到当前的 Map 对象中。 语法: public function putAll($values): void 参数: $values: 一个迭代器或关联数组,包含要添加到 Map 中的键值对。 示例: // 使用关联数组作为参数调用 putAll() 函数 $map = new Ds\Map([1 => 'one', 2 => 'two']); $map->putAll([3 => 'three', 4 => 'four']); print_r($map); 输出: Ds\Map Object ( [0] => Array ( [1] => one [2] => two [3] => three [4] => four ) ) // 使用迭代器作为参数调用 putAll() 函数 $map = new Ds\Map([1 => 'one', 2 => 'two']); $set = new Ds\Set(['three', 'four']); $map->putAll($set); print_r($map); 输出: Ds\Map Object ( [0] => Array ( [1] => one [2] => two [0] => three [1] => four ) ) 注意事项: 如果要添加的键已经存在于 Map 中,则原有的值将被替换为新的值。 如果要添加的值是一个迭代器,它将被转换为关联数组,其中的键将被丢弃,只保留值。