PHP - Ds Deque::__construct() Function



The PHP Ds\Deque::__construct() function is used to create a new instance of a deque. This new instance refers to an object of the Ds\Deque class.

Syntax

Following is the syntax of the PHP Ds\Deque::__construct() function −

public Ds\Deque::__construct(mixed $values = ?)

Parameters

Following is the parameter of this function −

  • values − A traversable object or an array to use for the initial values.

Return value

This function does not return any value.

Example 1

The following is the basic example of the PHP Ds\Deque::__construct() function −

<?php
   $deque = new \Ds\Deque();
   print_r($deque);
   # declare another deque
   $deque  = new \DS\Deque([10, 20, 30]);
   print_r($deque);
?>

Output

The above program produces the following output −

Ds\Deque Object
(
)
Ds\Deque Object
(
    [0] => 10
    [1] => 20
    [2] => 30
)

Example 2

Following is another example of the PHP Ds\Deque::__construct() function. We use this function to create new instances −

<?php
   $deque = new \Ds\Deque(['a', 'e', 'i']);
   print_r($deque);
   # declare another deque
   $deque  = new \DS\Deque(['a', 'e', 'i', 'o', 'u']);
   print_r($deque);
?>

Output

After executing the above program, the following output will be displayed −

Ds\Deque Object
(
    [0] => a
    [1] => e
    [2] => i
)
Ds\Deque Object
(
    [0] => a
    [1] => e
    [2] => i
    [3] => o
    [4] => u
)
php_function_reference.htm
Advertisements