This article mainly introduces the introduction of PHP double-stranded table (SplDoublyLinkedList) and related information about using instances. For more information, see the double-stranded table as an important linear storage structure, each node in a double-stranded table not only stores its own information, but also stores the address of the front-end and subsequent nodes.
The spldoublyshortlist class in php spl provides operations on double-stranded tables.
The summary of the spldoublyshortlist class is as follows:
Spldoublyshortlist implements Iterator, ArrayAccess, Countable {public _ construct (void) public void add (mixed $ index, mixed $ newval) // the header node of the double-stranded table public mixed top (void) // public mixed bottom (void) at the end of the double-Link Table // public int count (void) for the number of elements in the double-Link Table // checks whether the double-Link Table is empty public bool isEmpty (void) // The current node index public mixed key (void) // move to the previous record public void prev (void) // move to the next record public void next (void) // The current record public mixed current (void) // point the pointer to the beginning of the iteration public void rewind (void) // check whether the double-linked table has a node public bool valid (void) // specify whether the node at the index has the public bool offsetExists (mixed $ index) // obtain the value of the node at the specified index public mixed offsetGet (mixed $ index) // set the value of public void offsetSet (mixed $ index, mixed $ newval) at the specified index. // Delete the public void offsetUnset (mixed $ index) at the specified index) // The public mixed pop (void) element pops up from the end of the double-stranded table // Add the element to the end of the double-stranded table public void push (mixed $ value) // serialized storage public string serialize (void) // deserialize public void unserialize (string $ serialized) // sets the public void setIteratorMode (int $ mode) of the iteration mode) // obtain the iterative mode spldoublyshortlist: IT_MODE_LIFO (Stack style) spldoublyshortlist: IT_MODE_FIFO (Queue style) public int getIteratorMode (void) // remove the public mixed shift (void) element from the header of the double-stranded table // Add the public void unshift (mixed $ value) element to the header of the double-stranded table )}
Easy to use
$list = new SplDoublyLinkedList();$list->push('a');$list->push('b');$list->push('c'); $list->unshift('top');$list->shift(); print_r(array( 'pop' => $list->pop(), 'count' => $list->count(), 'isEmpty' => $list->isEmpty(), 'bottom' => $list->bottom(), 'top' => $list->top())); $list->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);print_r($list->getIteratorMode()); for($list->rewind(); $list->valid(); $list->next()) { echo $list->current().PHP_EOL;} print_r($a = $list->serialize());//print_r($list->unserialize($a)); $list->offsetSet(0,'new one');$list->offsetUnset(0);print_r(array( 'offsetExists' => $list->offsetExists(4), 'offsetGet' => $list->offsetGet(0), ));print_r($list);