Tutorial on PHP stack and queue learning _php

Source: Internet
Author: User
Arrays in PHP are often used as stacks (LIFO: LIFO) with the queue (first-out: FIFO) structure. PHP provides a set of functions that can be used for push with pop (stack) and shift with Unshift (queue) to manipulate array elements. Stacks and queues are widely used in practice.
We can look at the stack first:
Copy CodeThe code is as follows:
$arr = Array ();
Array_push ($arr, ' AAA ');
Array_push ($arr, ' BBB ');
$arr. Pop ();
Print_r ($arr);
?>

If you intend to use the array as a queue (FIFO), you can use Array_unshift () to add elements, using Array_shift () to delete:
Copy CodeThe code is as follows:
$arr = Array ();
Array_unshift ($arr, ' AAA ');
Array_unshift ($arr, ' BBB ');
Print_r ($arr);
Array_shift ($arr);
Print_r ($arr);
?>

http://www.bkjia.com/PHPjc/327789.html www.bkjia.com true http://www.bkjia.com/PHPjc/327789.html techarticle Arrays in PHP are often used as stacks (LIFO: LIFO) with the queue (first-out: FIFO) structure. PHP provides a set of functions that can be used for push vs. Pop (stack) and shift with ...

  • 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.