If we are not interested in implementing our own version of a stack, we can use the existing SPL implementation for stacks. It is very easy to use and requires minimal code to write. As we already know, SplStack uses SplDoublyLinkedList. It has all possible operations to push, pop, move forward, backward, shift, unshift, and so on. In order to implement the same example we saw previously, we have to write the following lines:
$books = new SplStack();
$books->push("Introduction to PHP7");
$books->push("Mastering JavaScript");
$books->push("MySQL Workbench tutorial");
echo $books->pop() . "\n";
echo $books->top() . "\n";
Yes, it is this simple to build a stack using the SplStack class. It is up to us to decide whether we want to implement it using a PHP array, a linked list, or a built...