Home > Backend Development > PHP Tutorial > Learn about PHP stack and queue_PHP tutorial

Learn about PHP stack and queue_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:04:06
Original
968 people have browsed it

In PHP, arrays are often used as stack (last in first out: LIFO) and queue (first in first out: FIFO) structures. PHP provides a set of functions that can be used to push and pop (stack) and shift and unshift (queue) to operate array elements. Stacks and queues are widely used in practice.
We can take a look at the stack first:

Copy the code The code is as follows:

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

If you plan to use the array as a queue (FIFO), you can use array_unshift() to add elements and array_shift() to delete:
Copy code The code is as follows:

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327789.htmlTechArticleIn PHP, arrays are often treated as stacks (last in, first out: LIFO) and queues (first in, first out: FIFO) ) structure to use. PHP provides a set of functions that can be used for push and pop (stack) as well as shift and...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template