Blogger Information
Blog 5
fans 0
comment 0
visits 3961
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP标准库:栈、堆、队列、定长数组
Original
953 people have browsed it

PHP标准库:栈、堆、队列、定长数组

栈:先进后出

  1. $stack = new SplStack();
  2. $stack->push("data1\n");
  3. $stack->push("data2\n");
  4. echo $stack->pop(); # data2
  5. echo "<br>";
  6. echo $stack->pop(); # data1

堆 (不了解)

  1. $minheap = new SplMinHeap();
  2. $minheap->insert("data1\n");
  3. $minheap->insert("data2\n");
  4. echo $minheap->extract(); # data1
  5. echo "<br>";
  6. echo $minheap->extract(); # data2

队列 先进先出

  1. $queue = new SplQueue(); //队列 先进先出
  2. $queue->enqueue("data1\n"); //入队
  3. $queue->enqueue("data2\n");
  4. echo $queue->dequeue(); #data1
  5. echo "<br>";
  6. echo $queue->dequeue(); #data2

定长数组(对象)

  1. $array = new SplFixedArray(10); # 定义 定长数组(对象)
  2. $array[4] = 5; # 定长数组(对象)无论是否使用,都会分配内存空间。
  3. # $array[10] = 10; # 超出分配的内存空间导致500错误。
  4. var_dump($array[4]); # 打印使用过的内存空间
  5. var_dump($array); # 打印全部分配的内存空间
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!