PHP stack and queuing Learning

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.