Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

PHP | Ds\Vector merge() Function

  • Last Updated : 30 Jun, 2021

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




<?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 vector
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




<?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 vector
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
 




My Personal Notes arrow_drop_up
Recommended Articles
Page :