PHP | Ds\Stack __construct() Function
The Ds\Stack::__construct() function is an inbuilt function in PHP which is used to create a new instance of stack.
Syntax:
public Ds\Stack::__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\Stack::__construct() function in PHP:
Program 1:
<?php // Declare a new stack $stack = new \Ds\Stack(); print_r($stack); // Declare a new stack $stack = new \Ds\Stack(['G', 'E', 'K', 'S']); print_r($stack); ?> |
Ds\Stack Object
(
)
Ds\Stack Object
(
[0] => S
[1] => K
[2] => E
[3] => G
)
Program 2:
<?php // Declare a new stack $stack = new \Ds\Stack([2, 3, 6, 7, 8]); var_dump($stack); // Declare a new stack $stack = new \Ds\Stack([2, 3, 5, 8, 9, 10]); var_dump($stack); ?> |
object(Ds\Stack)#1 (5) {
[0]=>
int(8)
[1]=>
int(7)
[2]=>
int(6)
[3]=>
int(3)
[4]=>
int(2)
}
object(Ds\Stack)#2 (6) {
[0]=>
int(10)
[1]=>
int(9)
[2]=>
int(8)
[3]=>
int(5)
[4]=>
int(3)
[5]=>
int(2)
}
Reference: https://www.php.net/manual/en/ds-stack.construct.php
Recommended Posts:
- What is the difference between a language construct and a “built-in” function in PHP ?
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- PHP Ds\Set get() Function
- D3.js | d3.lab() Function
- PHP | Ds\Set add() Function
- D3.js | d3.hcl() Function
- PHP Ds\Set sum() Function
- D3.js | d3.rgb() Function
- p5.js | nfs() Function
- p5.js | str() function
- p5.js | nfc() function
- PHP | Ds\Set contains() Function
- p5.js | int() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



