PHP | Ds\Vector merge() Function
The Ds\Vector::merge() function is an inbuilt function in PHP which is used to merge all the elements to the vector.
Syntax:
Ds\Vector public Ds\Vector::merge( $values )
Parameters: This function accepts a single parameter $values which is the traversable object or array.
Return Value: This function returns the copy of the vector after merging the elements to the vector.
Below programs illustrate the Ds\Vector::merge() function in PHP:
Program 1:
<?php // Create new vector $arr1 = new \Ds\Vector([10, 20, 30, 40, 50]); echo("Original vector elements\n"); print_r($arr1); // Create new vector $arr2 = new \Ds\Vector([60, 70, 80, 90, 100]); echo("Vector Elements after merging\n"); // Use merge() function to merge two vector // and display its resultant vactor print_r($arr1->merge($arr2)); ?> |
Output:
Original vector elements
Ds\Vector Object
(
[0] => 10
[1] => 20
[2] => 30
[3] => 40
[4] => 50
)
Vector Elements after merging
Ds\Vector Object
(
[0] => 10
[1] => 20
[2] => 30
[3] => 40
[4] => 50
[5] => 60
[6] => 70
[7] => 80
[8] => 90
[9] => 100
)
Program 2:
<?php // Create new vector $arr1 = new \Ds\Vector(["geeks", "for", "geeks"]); echo("Original vector elements\n"); print_r($arr1); // Create new vector $arr2 = new \Ds\Vector([60, 70, 100]); echo("Vector Elements after merging\n"); // Use merge() function to merge two vector // and display its resultant vactor print_r($arr1->merge($arr2)); ?> |
Output:
Original vector elements
Ds\Vector Object
(
[0] => geeks
[1] => for
[2] => geeks
)
Vector Elements after merging
Ds\Vector Object
(
[0] => geeks
[1] => for
[2] => geeks
[3] => 60
[4] => 70
[5] => 100
)
Reference: http://php.net/manual/en/ds-vector.merge.php
Recommended Posts:
- PHP | Ds\Set merge() Function
- PHP | Ds\Map merge() Function
- D3.js | d3.merge() function
- PHP | Ds\Sequence merge() Function
- PHP | Ds\Deque merge() Function
- How to merge two PHP objects?
- Git-Checkout And Merge
- How to merge the duplicate value in multidimensional array in PHP ?
- How to merge properties of two JavaScript objects dynamically?
- Merge two arrays keeping original keys in PHP
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- p5.js | min() function
- p5.js | sq() function
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.



