HomeLanguagesPHP | DsDeque __construct() Function

PHP | Ds\Deque __construct() Function

The Ds\Deque::__construct() function is an inbuilt function in PHP which is used to create a new instance.

Syntax:

Ds\Deque::__construct( $values )

Parameters: This function accepts single parameter $values which holds the traversable object or array to use initial values.

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

Program 1:




<?php 
  
// Declare a deque 
$deq = new \Ds\Deque();
  
// Display the elements of deque
echo("Elements of first deque:\n"); 
var_dump($deq);
  
// Declare a deque 
$deq = new \Ds\Deque([10, 20, 30, 40, 50, 60]); 
  
// Display the elements of deque
echo("\nElements of second deque:\n"); 
var_dump($deq);
  
?>


Output:

Elements of first deque:
object(Ds\Deque)#1 (0) {
}

Elements of second deque:
object(Ds\Deque)#2 (6) {
  [0]=>
  int(10)
  [1]=>
  int(20)
  [2]=>
  int(30)
  [3]=>
  int(40)
  [4]=>
  int(50)
  [5]=>
  int(60)
}

Program 2:




<?php 
  
// Declare a deque 
$deq = new \Ds\Deque(["neveropen", "for", "neveropen"]); 
  
// Display the elements of deque
echo("Elements of first deque:\n"); 
print_r($deq);
  
// Declare a deque 
$deq = new \Ds\Deque(['G', 'E', 'E', 'K', 'S', 1, 2, 3]); 
  
// Display the elements of deque
echo("\nElements of second deque:\n"); 
print_r($deq);
  
?>


Output:

Elements of first deque:
Ds\Deque Object
(
    [0] => neveropen
    [1] => for
    [2] => neveropen
)

Elements of second deque:
Ds\Deque Object
(
    [0] => G
    [1] => E
    [2] => E
    [3] => K
    [4] => S
    [5] => 1
    [6] => 2
    [7] => 3
)

Reference: https://www.php.net/manual/en/ds-deque.construct.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
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS