This article mainly introduces the introduction of PHP double-stranded table (spldoublyshortlist) and related information on using instances. For more information, see
This article mainly introduces the introduction of PHP double-stranded table (spldoublyshortlist) and related information on using instances. For more information, see
A double-chain table is an important linear storage structure. For each node in a double-chain table, it not only stores its own information, but also stores the addresses 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 spldoublyasklist (); $ 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 (spldoubly1_list: 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 );