What is the SplStack class for?

1

According to PHP:

  The SplStack class provides the main functionalities of a stack implemented using a doubly linked list.

What do you mean:

  

The SplStack class provides the key functionality of a stack deployed using a double-linked list.

Although the PHP Manual does try to offer some examples, nothing is very clear (in most cases).

This gives me some doubts when using it, since I do not usually see any PHP programmer go around saying, "Use the SplStack class to do this or that."

So, in practice, what would I be able to use the SplStack class?

    
asked by anonymous 17.08.2015 / 17:44

1 answer

3

SplStack is a class of the standard PHP Library (SPL -> Standard PHP Library). It belongs to the data structure group: link

On what this class does, the name itself already suggests. Stack is stack (data stacking).

This class acts as a reverse array, where data is being stacked, unlike a common array where data is given the next position.

Example:

$stack = new SplStack();

$stack[] = 1;
$stack[] = 2;
$stack[] = 3;

foreach ($stack as $item)  {
    echo $item, PHP_EOL;
}

The output in the case will be:

3
2
1
    
17.08.2015 / 18:10