Ds \ Vector::merge()函数是PHP中的内置函数,用于将所有元素合并到向量中。
用法:
Ds\Vector public Ds\Vector::merge( $values )
参数:此函数接受单个参数$values,它是可遍历的对象或数组。
返回值:在将元素合并到向量后,此函数返回向量的副本。
以下示例程序旨在说明PHP中的Ds \ Vector::merge()函数:
程序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));
?>
输出:
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 )
程序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));
?>
输出:
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 )
参考: http://php.net/manual/en/ds-vector.merge.php
相关用法
- PHP Ds\Map merge()用法及代码示例
- d3.js d3.merge()用法及代码示例
- PHP Ds\Set merge()用法及代码示例
- PHP Ds\Sequence merge()用法及代码示例
- PHP Ds\Deque merge()用法及代码示例
- PHP pos()用法及代码示例
注:本文由纯净天空筛选整理自barykrg大神的英文原创作品 PHP | Ds\Vector merge() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。