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)
?>