PHP | Ds\Deque::merge() Function

PHP Ds\Deque::merge() Function

Hello dear readers! welcome back to another edition of our tutorial on PHP. In this tutorial guide, we are going to be discussing about the PHP Ds Deque merge() Function.

The built-in PHP Ds Deque merge() function can return the result of adding all the given values to the deque, effectively the same as adding values to a copy and then return the copy.

Syntax

Following below is the syntax to use this function -

public Ds\Deque Ds\Deque::merge( mixed $values )


Return Value

This function returns the result of adding all the given values to the deque.

Example1

Try out the below example -

<?php 
   $deque1 = new \Ds\Deque([10, 20, 30, 40, 50]); 
   echo("The elements in first deque: \n"); 
   print_r($deque1); 
   
   $deque2 = new \Ds\Deque([60, 70, 80, 90]); 
   echo("\n The elements of second deque: \n"); 
   print_r($deque2); 
   
   echo("\n The merged deque elements: \n"); 
   print_r($deque1->merge($deque2)); 
?> 

Example2

Try the following example -

<?php 
   $deque1 = new \Ds\Deque(["Web", "Design", "Tutorialz"]); 
   echo("The elements in first deque: \n"); 
   print_r($deque1); 
   
   $deque2 = new \Ds\Deque(["Tutorialz", "Nigeria"]);
   echo("\n The elements of second deque: \n"); 
   print_r($deque2); 
   
   echo("\n The merged deque elements: \n"); 
   print_r($deque1->merge($deque2)); 
?> 


Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial guide, we are going to be discussing about the PHP Ds Deque pop() Function.

Do feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.