Speed up development with full-stack environments for every branch.

Learn More

How to implement the SplStack class [PHP]

295 Runs 1191 Views 398 Copies


gtsolutions 373

published 4 years ago


 * PHP SPL - How to implement the SplStack class

//Think of the stack as an array reversed, where the last element has index zero
$stack = new SplStack();
//push method adds the element at the begining of the stack

//rewind iterator back to the start

//pop method removes an element from the end of the stack

//iterate the stack and echo each element
while ($stack->valid()) {
    echo $stack->current(), PHP_EOL;
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).