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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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));
  
?>

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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));
  
?>

chevron_right


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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.