Ds \ Deque::merge()函數是PHP中的一個內置函數,用於通過將所有Deque的所有元素合並到一個副本中並將所有值添加到副本中來返回合並的Deque,然後返回該副本。
用法:
public Ds\Deque::merge( $values ):Ds\Deque
參數:此函數接受單個參數$values,其中包含要與調用Deque合並的值。
返回值:此函數返回一個雙端隊列,其中包含兩個雙端隊列的所有元素。
以下示例程序旨在說明PHP中的Ds \ Deque::merge()函數:
程序1:
<?php
// Declare a deque
$deck = new \Ds\Deque([10, 20, 30, 40, 50, 60]);
echo("Elements of first deque\n");
// Display the deque Elements
print_r($deck);
// Declare another deque
$deck2 = new \Ds\Deque([70, 80, 90, 100]);
echo("\nElements of second deque\n");
print_r($deck2);
echo("\nMerged deque elements\n");
// Merge the both deque
print_r($deck->merge($deck2));
?>
輸出:
Elements of first deque Ds\Deque Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 [5] => 60 ) Elements of second deque Ds\Deque Object ( [0] => 70 [1] => 80 [2] => 90 [3] => 100 ) Merged deque elements Ds\Deque Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 [5] => 60 [6] => 70 [7] => 80 [8] => 90 [9] => 100 )
程序2:
<?php
// Declare a deque
$deck = new \Ds\Deque(["geeks", "for", "geeks"]);
echo("Elements of first deque\n");
// Display the deque Elements
print_r($deck);
// Declare another deque
$deck2 = new \Ds\Deque(["practicing", "data", "structures"]);
echo("\nElements of second deque\n");
print_r($deck2);
echo("\nMerged deque elements\n");
// Merge the both deque
print_r($deck->merge($deck2));
?>
輸出:
Elements of first deque Ds\Deque Object ( [0] => geeks [1] => for [2] => geeks ) Elements of second deque Ds\Deque Object ( [0] => practicing [1] => data [2] => structures ) Merged deque elements Ds\Deque Object ( [0] => geeks [1] => for [2] => geeks [3] => practicing [4] => data [5] => structures )
參考: http://php.net/manual/en/ds-deque.merge.php
相關用法
- d3.js d3.merge()用法及代碼示例
- PHP Ds\Set merge()用法及代碼示例
- PHP Ds\Map merge()用法及代碼示例
- PHP Ds\Vector merge()用法及代碼示例
- PHP Ds\Sequence merge()用法及代碼示例
- PHP Ds\Set add()用法及代碼示例
注:本文由純淨天空篩選整理自barykrg大神的英文原創作品 PHP | Ds\Deque merge() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。