php8.5
Home/ Manual/ ds / stack/ Ds\Stack::__construct

Ds\Stack::__construct

PHP function Edit on GitHub ✎

(PECL ds >= 1.0.0)

Creates a new instance

Description

Ds\Stack::__construct([mixed $values])

Creates a new instance, using either a traversable object or an Array for the initial values.

Parameters

values

A traversable object or an Array to use for the initial values.

Examples

Ds\Stack::__construct() example

php
<?php
$stack = new \Ds\Stack();
print_r($stack);

$stack = new \Ds\Stack([1, 2, 3]);
print_r($stack);
?>

The above example will output something similar to:

output
Ds\Stack Object
(
)
Ds\Stack Object
(
    [0] => 3
    [1] => 2
    [2] => 1
)

Source: reference/ds/ds/stack/construct.xml · from the official PHP manual (php/doc-en)