What’s the Splstack class for?

Asked

Viewed 134 times

1

According to the 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 functionalities of an implemented stack using a double-linked list.

Although the PHP Handbook tries to offer some examples, nothing is very clear (in most cases).

This raises some questions when using, since I don’t usually see any PHP programmers go around saying: "Use the class SplStack to do this or that".

So in practice, so I could use the class SplStack?

1 answer

3


The SplStack is a class in the standard PHP library (SPL -> Standard PHP Library). Belongs to the data structure group: http://php.net/manual/en/spl.datastructures.php

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

This class acts as a reverse array, where the data is being stacked, unlike a common array where the 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 exit in case will be:

3
2
1
  • Daniel, do you mind if I add an example (code) to your reply?

  • All right... the answer is not mine.. it’s from the community. Shoot.!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.