PHP stack writing

Source: Internet
Author: User
: 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.

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.