$stack = new SplStack();$stack->push("data1\n");$stack->push("data2\n");echo $stack->pop(); # data2echo "<br>";echo $stack->pop(); # data1
$minheap = new SplMinHeap();$minheap->insert("data1\n");$minheap->insert("data2\n");echo $minheap->extract(); # data1echo "<br>";echo $minheap->extract(); # data2
$queue = new SplQueue(); //队列 先进先出$queue->enqueue("data1\n"); //入队$queue->enqueue("data2\n");echo $queue->dequeue(); #data1echo "<br>";echo $queue->dequeue(); #data2
$array = new SplFixedArray(10); # 定义 定长数组(对象)$array[4] = 5; # 定长数组(对象)无论是否使用,都会分配内存空间。# $array[10] = 10; # 超出分配的内存空间导致500错误。var_dump($array[4]); # 打印使用过的内存空间var_dump($array); # 打印全部分配的内存空间
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号