La función Ds\Deque::push() es una función incorporada en PHP que se usa para agregar los elementos a Deque agregando un elemento al final de Deque.
Sintaxis:
public Ds\Deque::push( $values ) : void
Parámetros: esta función acepta valores de $de parámetro único que contiene los elementos que se agregarán al Deque.
Valor devuelto: esta función no devuelve ningún valor.
Los siguientes programas ilustran la función Ds\Deque::push() en PHP:
Programa 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); ?>
Producción:
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 )
Programa 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); ?>
Producción:
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 )
Referencia: http://php.net/manual/en/ds-deque.push.php