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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。