📜  PHP | Ds\Deque push()函数

📅  最后修改于: 2022-05-13 01:56:56.235000             🧑  作者: Mango

PHP | Ds\Deque push()函数

Ds\Deque::push()函数是PHP中的一个内置函数,用于通过在 Deque 末尾附加一个元素来将元素添加到 Deque。

句法:

public Ds\Deque::push( $values ) : void

参数:此函数接受单个参数$values ,它保存要添加到双端队列的元素。

返回值:此函数不返回任何值。

下面的程序说明了PHP中的Ds\Deque::push()函数:

方案一:

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
)

方案二:

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。 PHP