The Ds\Deque::merge() function is an inbuilt function in PHP which is used to return the merged Deque after merging all the elements of one Deque with another by adding all the values into a copy and returns that copy.
Syntax:
public Ds\Deque::merge( $values ) : Ds\Deque
Parameters: This function accepts single parameter $values which contains the values to be merged with the calling Deque.
Return Value: This function returns a Deque which contains all the elements of both the Deque.
Below programs illustrate the Ds\Deque::merge() function in PHP:
Program 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)); ?> |
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
)
Program 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)); ?> |
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
)
Reference: http://php.net/manual/en/ds-deque.merge.php
Recommended Posts:
- PHP | Ds\Sequence merge() Function
- PHP | Ds\Vector merge() Function
- PHP | Ds\Set merge() Function
- PHP | Ds\Map merge() Function
- Merge two arrays keeping original keys in PHP
- How to merge two PHP objects?
- How to merge the duplicate value in multidimensional array in PHP ?
- How to merge arrays and preserve the keys in PHP ?
- D3.js | d3.merge() function
- D3.js selection.merge() Function
- How to merge properties of two JavaScript objects dynamically?
- Git-Checkout And Merge
- ES6 | Merge Objects
- JQuery | merge() method
- How to merge the first index of an array with the first index of second array?
- How to Merge/Combine Arrays using JavaScript ?
- Underscore.js _.merge() Method
- Lodash _.merge() Method
- Collect.js merge() Method
- How to get the function name inside a function in PHP ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

