Data structure stack (SplStack) in the PHPSPL standard library. Introduction to the data structure Stack (SplStack) in the PHPSPL standard library. the splsplstack Stack is a special linear table, because it can only insert or delete elements at one end of a linear table (that is, Introduction to the data structure stack (SplStack) of the php spl standard library), splsplstack
Stack is a special linear table, because it can only insert or delete elements at one end of the linear table (that is, the elements going into and out of the Stack)
SplStack inherits the double-stranded table (spldoublyshortlist) to implement the stack.
Class abstract:
Simple use:
// Think of the stack as an inverted array $ stack = new SplStack ();/*** the difference between the stack and the double-stranded table is that IteratorMode has changed, stack IteratorMode can only be: * (1) SplDoublyLinkedList: IT_MODE_LIFO | SplDoublyLinkedList: Greatest (default value: Save data after iteration) * (2) SplDoublyLinkedList: Greatest | SplDoublyLinkedList :: IT_MODE_DELETE (delete data after iteration) */$ stack-> setIteratorMode (spldoubly1_list: IT_MODE_LIFO | spldoubly1_list: IT_MODE_DELETE); $ stack-> push ('A '); $ stack-> push ('B'); $ stack-> push ('C'); $ stack-> pop (); // output stack $ stack-> offsetSet (0, 'First '); // The last element foreach ($ stack as $ item) {echo $ item is 0. PHP_EOL; // first a} print_R ($ stack); // Test IteratorMode
Introduction to the data structure Stack (SplStack) of http://www.bkjia.com/PHPjc/998569.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/998569.htmlTechArticlePHP SPL standard library, SPLS Stack is a special linear table, because it can only insert or delete elements at one end of a linear table (that is, the elements are pushed to the stack and output...