Common Data Structures in the SPL standard library and spl Standard Data Structures
Stack data structure
1 $ stack = new SplStack (); // stack data structure-> advanced 2 $ stack-> push ('data1 '); // stack 3 $ stack-> push ('data2 '); // stack 4 echo $ stack-> pop (); // stack-> data25 echo $ stack-> pop (); // stack-> data1
Queue Data Structure
1 $ queue = new SplQueue (); // queue Data Structure-> first-in-first-out 2 $ queue-> enqueue ('data1 '); // column 3 $ queue-> enqueue ('data2 '); // column 4 echo $ queue-> dequeue (); // output column-> data15 echo $ queue-> dequeue (); // output column-> data2
Heap Data Structure
1 $ heap = new SplMinHeap (); // heap Data Structure 2 $ heap-> insert ('data1 '); // store 3 $ heap-> insert ('data2 '); // store 4 echo $ heap-> extract (); // retrieve-> data15 echo $ heap-> extract (); // retrieve-> data2
Array data structure with Fixed Length
1 $ array = new SplFixedArray (10); // an array with a fixed length. The declared length is 102 $ array [0] = 0; 3 $ array [9] = 9; 4 var_dump ($ array); 5 // object (SplFixedArray) #1 (10) {[0] => int (0) [1] => NULL [2] => NULL [3] => NULL [4] => NULL [5] => NULL [6] => NULL [7] => NULL [8] => NULL [9] => int (9 )} 6 // no matter whether the subscript is used or not, the memory space will be allocated.