PHP中 SPL标准库
in PHPer技术 with 0 comment

PHP中 SPL标准库

in PHPer技术 with 0 comment

//固定长度数组
$array = new  SplFixedArray(10);
$array[0] = 123;
$array[9] = 1234;
var_dump($array);




//堆
$heap = new  SplMinHeap();
$heap->insert("data1");
$heap->insert("data2");
echo $heap->extract();
echo $heap->extract();



//队列 先进先出 后进后出
$queue = new SplQueue();
$queue->enqueue("data1\n");
$queue->enqueue("data2\n");

echo $queue->dequeue();
echo $queue->dequeue();



//栈 后进先出
$stack = new SplStack();
$stack->push("data1\n");
$stack->push("data2\n");

echo $stack->pop();
echo $stack->pop();


Responses