La función Ds\Map::merge() es una función incorporada en PHP que se usa para devolver el resultado de agregar todas las asociaciones dadas.
Sintaxis:
Ds\Map public Ds\Map::merge( $values )
Parámetro: esta función acepta valores de $de parámetro único que contiene el objeto transitable o una array.
Valor de retorno: esta función devuelve la asociación de todas las claves de un objeto o array transitable dado con sus valores correspondientes, combinados con la instancia actual.
Los siguientes programas ilustran la función Ds\Map::merge() en PHP:
Programa 1:
<?php // Create new map $map = new \Ds\Map(["a" => 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) ?>
Producción:
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 ) )
Programa 2:
<?php // Create new map $map = new \Ds\Map(["1" => "Geeks", "2" => "for", "3" => "Geeks"]); // Merge the map element and display it print_r($map->merge(["a" => "Computer", "b" => "Science", "c" => "Portal"])); ?>
Producción:
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 ) )
Referencia: https://www.php.net/manual/en/ds-map.merge.php