PHP SPL standard library data structure stack (Splstack) Introduction
This article mainly introduces the PHP SPL standard library data structure stack (splstack) Introduction, stack (stack) is a special linear table, because it can only at one end of the linear table to insert or delete elements (i.e., into the stack and out of the stack), the need for friends can refer to the next
A stack is a special linear table because it can only insert or delete elements at one end of a linear table (that is, the stack and the stack)
Splstack is the inherited doubly linked list (spldoublylinkedlist) implementation stack.
The class summary is as follows:
Simple to use as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21st |
Think of the stack as an inverted array $stack = new Splstack (); /** * The difference between the visible stack and the doubly linked list is that Iteratormode has changed, and the stack's Iteratormode can only be: * (1) spldoublylinkedlist::it_mode_lifo | Spldoublylinkedlist::it_mode_keep (default value, data save after iteration) * (2) Spldoublylinkedlist::it_mode_lifo | Spldoublylinkedlist::it_mode_delete (data deduplication after iteration) */ $stack->setiteratormode (Spldoublylinkedlist::it_mode_lifo | Spldoublylinkedlist::it_mode_delete); $stack->push (' a '); $stack->push (' B '); $stack->push (' C '); $stack->pop (); Out of the stack $stack->offsetset (0, ' first ');//index to 0 is the last element foreach ($stack as $item) { Echo $item. Php_eol; First A } Print_r ($stack); Test Iteratormode |
http://www.bkjia.com/PHPjc/1000109.html www.bkjia.com true http://www.bkjia.com/PHPjc/1000109.html techarticle PHP SPL standard library data structure stack (Splstack) Introduction This article mainly introduces the PHP SPL standard library data structure stack (splstack) Introduction, stack (stack) is a special linear table, because it can only ...