PHP code that uses arrays to implement the stack data structure. In the stack, the final pushed data (into the stack) will be first popped up (out of the stack ). That is, the data structure is "advanced and later" in data storage. In PHP, the array is regarded as a stack in the stack, and the final pushed data (into the stack) will be first popped up (out of the stack ).
That is, the data structure is "advanced and later" in data storage.
In PHP, the array is used as a stack, mainly using the array_push () and array_pop () system functions.
The array_push () function is used to add one or more elements to the end of the array of the first parameter, and then return the length of the new array. for example:
The code is as follows:
$ 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"); // Press an element.
Print_r ($ zhan); // Print the array content
?>
The output stack mainly uses the array_pop () function to bring up the last function of the array and reduce the length of the array by 1. the example is as follows:
The code is as follows:
$ Zhan = array ("WEB", "www.chhua.com", "WEB development notes", "PHP", "website construction"); // declare an array as a stack
Array_pop ($ zhan); // extract the string from the stack (array)
Print_r ($ zhan); // Print the Array content Array ([0] => WEB [1] => www.chhua.com [2] => WEB Development notes [3] => PHP)
?>
The producer (into the stack) will be first popped up (out of the stack ). That is, the data structure is "advanced and later" in data storage. In PHP, the array is treated as a stack...