Friday, September 27, 2024
Google search engine
HomeLanguagesPHP | DsDeque push() Function

PHP | Ds\Deque push() Function

The Ds\Deque::push() function is an inbuilt function in PHP which is used to add the elements to the Deque by appending an element at the end of the Deque.

Syntax:

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

Parameters: This function accepts single parameter $values which holds the elements to be added to the Deque.

Return Value: This function does not return any values.

Below programs illustrate the Ds\Deque::push() function in PHP:

Program 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);
  
?>


Output:

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
)

Program 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);
  
?>


Output:

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
)

Reference: http://php.net/manual/en/ds-deque.push.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments