Introduction and use of PHP double-stranded table

Source: Internet
Author: User

Introduction and use of PHP double-stranded table

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:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

Spldoublyasklist 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)

// Tail node of the double-stranded table

Public mixed bottom (void)

// Number of double join Table Elements

Public int count (void)

// Check whether the double-stranded table is empty

Public bool isEmpty (void)

 

 

// Index of the current node

Public mixed key (void)

// Move to the previous record

Public void prev (void)

// Move to the next record

Public void next (void)

// Current record

Public mixed current (void)

// Point the pointer to the beginning of the iteration

Public void rewind (void)

// Check whether there are nodes in the double-stranded table

Public bool valid (void)

 

// Specify whether a node exists at the index

Public bool offsetExists (mixed $ index)

// Obtain the node value at the specified index

Public mixed offsetGet (mixed $ index)

// Set the value at the specified index

Public void offsetSet (mixed $ index, mixed $ newval)

// Delete the node at the specified index

Public void offsetUnset (mixed $ index)

 

// Elements are displayed at the end of the double-stranded table.

Public mixed pop (void)

// Add elements to the end of the double-stranded table

Public void push (mixed $ value)

 

// Serialized Storage

Public string serialize (void)

// Deserialization

Public void unserialize (string $ serialized)

 

// Set the iteration Mode

Public void setIteratorMode (int $ mode)

// Obtain the iterative mode spldoublyshortlist: IT_MODE_LIFO (Stack style) spldoublyshortlist: IT_MODE_FIFO (Queue style)

Public int getIteratorMode (void)

 

// Remove the element from the header of the double-stranded table

Public mixed shift (void)

// Add an element to the header of the double-stranded table

Public void unshift (mixed $ value)

 

}

Easy to use

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

$ 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 ($ ));

 

$ List-> offsetSet (0, 'new one ');

$ List-> offsetUnset (0 );

Print_r (array (

'Offsetexists' => $ list-> offsetExists (4 ),

'Offsetget' => $ list-> offsetGet (0 ),

 

));

Print_r ($ list );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.