Home > Backend Development > PHP Tutorial > 关于PHP堆栈与列队的学习_php技巧

关于PHP堆栈与列队的学习_php技巧

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-17 08:59:54
Original
980 people have browsed it

在PHP中数组常被当作堆栈(后进先出:LIFO)与队列(先进先出:FIFO)结构来使用。PHP提供了一组函数可以用于push与pop(堆栈)还有shift与unshift(队列)来操作数组元素。堆栈与列队在实践中应用非常广泛。
我们可以先看下堆栈:
 

复制代码 代码如下:

    $arr = array();
   array_push($arr,'aaa');
   array_push($arr,'bbb');
   $arr.pop();
   print_r($arr);
?>
 

如果你打算把数组作为队列来使用(FIFO),你可以使用array_unshift()来增加元素,使用array_shift()删除:
复制代码 代码如下:

   $arr = array();
   array_unshift($arr,'aaa');
   array_unshift($arr,'bbb');
   print_r($arr);
   array_shift($arr);
   print_r($arr);
?>

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template