This article provides a detailed analysis of the stacks and queues in PHP. For more information, see
This article provides a detailed analysis of the stacks and queues in PHP. For more information, see
In PHP, arrays are often used as stacks (first-in-first-out: LIFO) and queues (first-in-first-out: FIFO. PHP provides a set of functions for pushing, pop (stack), and shift and unshift (Queue) to operate on array elements. Stacks and queues are widely used in practice.
Let's take a look at the next stack:
The Code is as follows:
$ Arr = array ();
Array_push ($ arr, 'aaa ');
Array_push ($ arr, 'bbb ');
$ Arr. pop ();
Print_r ($ arr );
?>
If you want to use arrays as queues (FIFO) and U.S. space, you can use array_unshift () to add elements, website space, and use array_shift () to delete:
The Code is as follows:
$ Arr = array ();
Array_unshift ($ arr, 'aaa ');
Array_unshift ($ arr, 'bbb ');
Print_r ($ arr );
Array_shift ($ arr );
Print_r ($ arr );
?>
, Website Space