PHP uses arrays to implement queues _php tips

Source: Internet
Author: User
PHP uses the array as a stack, mainly using Array_push () and Array_pop () two system functions to complete. The stack mainly uses the Array_push () function to add one or more elements to the tail of the first parameter, and then returns the length of the new array, as follows:
In PHP, the array as a queue is mainly implemented with Array_push () and Array_shift ().
Copy Code code as follows:

<?php
$zhan =array ("WEB");//Declare an array as a queue
Array_push ($zhan, "PHP");//Press the string into the stack (array)
Array_push ($zhan, "WWW.CHHUA.COM"), or press into an element
Print_r ($zhan);//print array contents
?>

The stack mainly uses the Array_shift () function to eject the first element of the array and subtract the length of the array by 1, as shown in the following example:
Copy Code code as follows:

<?php
$zhan =array ("Web", "www.chhua.com", "Web Development Notes", "PHP", "website building");/declare an array as a stack
Array_shift ($zhan);//Send string out of Team (array)
Print_r ($zhan);//print array content array ([0] => web[1] => www.chhua.com[2] => WEB Development notes [3] => PHP)
?>

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.