In the stack, the last pressed data (into the stack) will be first ejected (out of the stack).
That is, the "advanced out" data structure is used in the data storage.
In PHP, the array is treated as a stack, mainly by using Array_push () and Array_pop () two system functions.
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:
Copy Code code as follows:
<?php
$zhan =array ("WEB");//Declare an array as a stack
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_pop () function to eject the last function 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_pop ($zhan);//send string out of stack (array)
Print_r ($zhan);//print array content array ([0] => web[1] => www.chhua.com[2] => WEB Development notes [3] => PHP)
?>