: This article describes how to write a PHP stack. For more information about PHP tutorials, see. Yesterday's interview questions included an application of question stack. at that time, I knew the principle and did not write the code. I will write it today ..
End = null) {$ this-> end = 0;} else {$ this-> end ++ ;} $ this-> stack_arr [$ this-> end] = $ str;} public function pop () {// if ($ this-> end = null) {return false ;} // if this is the case, if (empty ($ this-> stack_arr) {return false ;} $ pop_data = $ this-> stack_arr [$ this-> end]; array_splice ($ this-> stack_arr, $ this-> end); $ this-> end --; return $ pop_data;} public function getData () {return $ this-> stack_arr ;}}$ arr = Array (); $ data_obj = new Stack (); $ data_obj-> push ("each one"); $ data_obj-> push ("2_two "); $ data_obj-> push ("3_three"); $ data_obj-> pop (); $ arr = $ data_obj-> getData (); print_r ($ arr);?>
Print result:
Bytes ---------------------------------------------------------------------------------------------------------------
Array ([0] => using one [1] => 2_two)
The above introduces the PHP stack writing method, including some content, and hopes to help friends who are interested in PHP tutorials.