Ds \ Deque::push()函數是PHP中的內置函數,用於通過在雙端隊列的末尾附加元素來將元素添加到雙端隊列。
用法:
public Ds\Deque::push( $values ):void
參數:此函數接受單個參數$values,該參數保存要添加到Deque中的元素。
返回值:此函數不返回任何值。
以下示例程序旨在說明PHP中的Ds \ Deque::push()函數:
程序1:
<?php
// Declare a deque
$deck = new \Ds\Deque([10, 20, 30, 40, 50, 60]);
echo("Elements of Deque\n");
// Display the Deque elements
print_r($deck);
echo("\nAdding 70 in the deque\n");
// Use push() function to add elements
$deck->push(70);
echo("\nElements of Deque\n");
// Display the Deque elements
print_r($deck);
?>
輸出:
Elements of Deque Ds\Deque Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 [5] => 60 ) Adding 70 in the deque Elements of Deque Ds\Deque Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 [5] => 60 [6] => 70 )
程序2:
<?php
// Declare a deque
$deck = new \Ds\Deque([10, 20, 30, 40, 50, 60]);
echo("Elements of Deque\n");
// Display the Deque elements
print_r($deck);
echo("\nAdding elements in the deque\n");
// Use push() function to add elements
$deck->push(...[70, 80, 90, 100]);
echo("\nElements of Deque\n");
// Display the Deque elements
print_r($deck);
?>
輸出:
Elements of Deque Ds\Deque Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 [5] => 60 ) Adding elements in the deque Elements of Deque Ds\Deque Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 [5] => 60 [6] => 70 [7] => 80 [8] => 90 [9] => 100 )
參考: http://php.net/manual/en/ds-deque.push.php
相關用法
- PHP Ds\PriorityQueue push()用法及代碼示例
- PHP Ds\Sequence push()用法及代碼示例
- PHP Ds\Queue push()用法及代碼示例
- Node.js push()用法及代碼示例
- PHP Ds\Vector push()用法及代碼示例
- PHP SplDoublyLinkedList push()用法及代碼示例
- PHP Ds\Stack push()用法及代碼示例
- CSS var()用法及代碼示例
注:本文由純淨天空篩選整理自barykrg大神的英文原創作品 PHP | Ds\Deque push() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。