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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。