Home > Article > Backend Development > How to implement queue structure in php (code)
The content of this article is about how to implement the queue structure (code) in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Problem Description
Use two stacks to implement a queue and complete the Push and Pop operations of the queue. The elements in the queue are of type int.
Idea:
1.php array can be completely implemented
2.array_push pushes elements from the tail
3.array_shift deletes elements from the head
$list=array(); array_push($list,$node); array_shift($list);
<?php $list=array(); function mypush($node) { global $list; array_push($list,$node); return $list; } function mypop() { global $list; return array_shift($list); }
The above is the detailed content of How to implement queue structure in php (code). For more information, please follow other related articles on the PHP Chinese website!