This article mainly introduces the data structure Stack of the PHPSPL standard library. Stack is a special linear table, because it can only insert or delete elements at one end of a linear table (that is, to Stack and to Stack), you can refer to the next Stack as a special linear table, because it can only insert or delete elements at one end of a linear table (that is, the elements in the stack and Out 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