Php Data Structure

There's what is called a "Data Structure" or DS package available in packagist.

Install

1~$ cd /an/isolated/directory
2~$ composer require php-ds/php-ds
3~$ composer install

Try this code:

 1<?php
 2require __DIR__ . '/vendor/autoload.php';
 3
 4
 5$stack = new \Ds\Stack();
 6//$stack = new Stack();
 7
 8$stack->push("a");
 9$stack->push("b");
10$stack->push("c");
11
12var_dump($stack->pop());
13var_dump($stack->pop());
14var_dump($stack->pop());
15?>

See https://www.php.net/manual/en/book.ds.php or https://medium.com/@rtheunissen/efficient-data-structures-for-php-7-9dda7af674cd