Home >Backend Development >PHP Tutorial >Detailed explanation of commonly used data structures in SPL in php
This article mainly shares with you a detailed explanation of the commonly used data structures of SPL in PHP. It is mainly shared with you in the form of code. I hope it can help you.
This article stack [First in, last out]
<span style="font-size:18px;">$stack = new SplStack(); $stack->push('data1'); $stack->push('data2'); $stack->push('data3'); echo $stack->pop(); //输出结果为 //data3</span><span style="font-size:24px;font-weight: bold;"> </span>
2. Queue [First in, first out, last in, last out]
<span style="font-size:18px;">$queue = new SplQueue(); $queue->enqueue("data1"); $queue->enqueue("data2"); $queue->enqueue("data3"); echo $queue->dequeue(); //输出结果为 //data1</span>
3. Heap
<span style="font-size:18px;">$heap = new SplMinHeap(); $heap->insert("data1"); $heap->insert("data2"); echo $heap->extract(); //输出结果为 //data1</span>
4. Fixed size array
<span style="font-size:18px;">$array = new SplFixedArray(5); $array[0]=1; $array[3]=3; $array[2]=2; var_dump($array); //输出结果为 // object(SplFixedArray)[1] // public 0 => int 1 // public 1 => null // public 2 => int 2 // public 3 => int 3 // public 4 => null</span>
Related recommendations:
JS data structure and algorithm detailed explanation of arrays and hash tables
javascript data structure and algorithm detailed explanation
PHP implements stack data structure and bracket matching
The above is the detailed content of Detailed explanation of commonly used data structures in SPL in php. For more information, please follow other related articles on the PHP Chinese website!