La función Ds\Deque::merge() es una función incorporada en PHP que se usa para devolver el Deque fusionado después de fusionar todos los elementos de un Deque con otro agregando todos los valores en una copia y devuelve esa copia.
Sintaxis:
public Ds\Deque::merge( $values ) : Ds\Deque
Parámetros: esta función acepta valores de $de parámetro único que contienen los valores que se fusionarán con el Deque que llama.
Valor de retorno: esta función devuelve un Deque que contiene todos los elementos de ambos Deque.
Los siguientes programas ilustran la función Ds\Deque::merge() en PHP:
Programa 1:
<?php // Declare a deque $deck = new \Ds\Deque([10, 20, 30, 40, 50, 60]); echo("Elements of first deque\n"); // Display the deque Elements print_r($deck); // Declare another deque $deck2 = new \Ds\Deque([70, 80, 90, 100]); echo("\nElements of second deque\n"); print_r($deck2); echo("\nMerged deque elements\n"); // Merge the both deque print_r($deck->merge($deck2)); ?>
Producción:
Elements of first deque Ds\Deque Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 [5] => 60 ) Elements of second deque Ds\Deque Object ( [0] => 70 [1] => 80 [2] => 90 [3] => 100 ) Merged deque elements Ds\Deque Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 [5] => 60 [6] => 70 [7] => 80 [8] => 90 [9] => 100 )
Programa 2:
<?php // Declare a deque $deck = new \Ds\Deque(["geeks", "for", "geeks"]); echo("Elements of first deque\n"); // Display the deque Elements print_r($deck); // Declare another deque $deck2 = new \Ds\Deque(["practicing", "data", "structures"]); echo("\nElements of second deque\n"); print_r($deck2); echo("\nMerged deque elements\n"); // Merge the both deque print_r($deck->merge($deck2)); ?>
Producción:
Elements of first deque Ds\Deque Object ( [0] => geeks [1] => for [2] => geeks ) Elements of second deque Ds\Deque Object ( [0] => practicing [1] => data [2] => structures ) Merged deque elements Ds\Deque Object ( [0] => geeks [1] => for [2] => geeks [3] => practicing [4] => data [5] => structures )
Referencia: http://php.net/manual/en/ds-deque.merge.php