Stack Implementation in PHP5 - Stack Class

Refer to the code below which is a PHP5 Stack Class - an implementation of Stacks. You are free to use it in your programs.




class Stack {
 
	private $stk = array();
 
	public function __construct() {
	}
 
	public function push($data) {
		array_push($this->stk, $data);
	}
 
	public function pop() {
		return array_pop($this->stk);
	}
 
}
 
$s = new Stack();
 
$s->push("Sunil");
$s->push("Bhatia");
 
echo $s->pop();
echo "\n";
echo $s->pop();

Please fee free to leave comments if you have any questions or suggestions. Also don’t forget to subscribe to the newsletter - to keep yourself updated as and when new posts are made live. Subscribe Below:

PHP5 Tutorial - Object Oriented Programming (OOPS)

  1. PHP5 Tutorial - Learn to create a PHP5 Class
  2. PHP5 Tutorial - Learn to Create a PHP5 Class Object
  3. PHP5 Tutorial - Defining Attributes of a PHP5 Class
  4. PHP5 Tutorial - Defining Methods of a PHP5 Class
  5. PHP5 Tutorial - Creating a PHP5 Constructor __construct()
  6. PHP5 Tutorial OOPS - Creating a PHP5 Destructor __destruct()
  7. PHP5 Tutorial OOPS - PHP5 Class Access Specifiers - public, private and protected
  8. PHP5 Tutorial - Magic Methods - __toString() method
  9. PHP5 Tutorial - Magic Methods - __get() and __set()
  10. PHP5 Tutorial - Magic Methods - __isset() and __unset()
  11. PHP5 Tutorial - Magic Methods - __call() method
  12. PHP5 Tutorial - Magic Methods - __autoload() method
  13. PHP5 Tutorial - Magic Methods - __sleep() and __wakeup()
  14. PHP5 Tutorial - Magic Methods - __clone() method

Your email:  
Subscribe Unsubscribe  

del.icio.us Reddit Slashdot Digg Facebook Technorati Google StumbleUpon Windows Live Furl Netscape Yahoo Bloglines Bookmark.it Ask Spurl Diigo

One Response to “Stack Implementation in PHP5 - Stack Class”

  1. why reinvent the wheel?

    user array_push() and array_pop()

Leave a Reply

Top Internet blogs Programming Blogs - Blog Catalog Blog Directory TopOfBlogs Technology blogs Top Blog Topsites List