Wednesday, November 20, 2024
Google search engine
HomeLanguagesPHP | DsDeque shift() Function

PHP | Ds\Deque shift() Function

The Ds\Deque::shift() function is an inbuilt function in PHP which is used to remove and return the first value of deque.

Syntax:

mixed Ds\Deque::shift( void )

Parameters: This function does not accept any parameters.

Return Value: This function returns the first value of deque which was removed.

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

Program 1:




<?php 
  
// Declare a deque 
$deq = new \Ds\Deque([10, 20, 30, 40, 50, 60]); 
  
// Use Ds\Deque::shift() function
var_dump($deq -> shift());
var_dump($deq -> shift());
var_dump($deq -> shift());
var_dump($deq -> shift());
var_dump($deq -> shift());
var_dump($deq -> shift());
  
?> 


Output:

int(10)
int(20)
int(30)
int(40)
int(50)
int(60)

Program 2:




<?php 
  
// Declare a deque 
$deq = new \Ds\Deque(["neveropen", "for", "neveropen"]); 
  
// Use Ds\Deque::shift() function
var_dump($deq -> shift());
var_dump($deq -> shift());
var_dump($deq -> shift());
  
// Declare a deque 
$deq = new \Ds\Deque(['G', 'E', 'E', 'K', 'S', 1, 2, 3]); 
  
// Use Ds\Deque::shift() function
var_dump($deq -> shift());
var_dump($deq -> shift());
var_dump($deq -> shift());
  
?>


Output:

string(5) "neveropen"
string(3) "for"
string(5) "neveropen"
string(1) "G"
string(1) "E"
string(1) "E"

Reference: https://www.php.net/manual/en/ds-deque.shift.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!

RELATED ARTICLES

Most Popular

Recent Comments