Skip to content

Instantly share code, notes, and snippets.

@mikemadisonweb
Forked from zachflower/Stack.class.php
Created August 24, 2016 13:24
Show Gist options
  • Save mikemadisonweb/f721661d0ff1b9280d99b076a27eba55 to your computer and use it in GitHub Desktop.
Save mikemadisonweb/f721661d0ff1b9280d99b076a27eba55 to your computer and use it in GitHub Desktop.
PHP implementation of a stack.
<?php
// http://www.cplusplus.com/reference/stack/stack/
class Stack {
private $_stack = array();
public function size() {
return count($this->_stack);
}
public function top() {
return end($this->_stack);
}
public function push($value = NULL) {
array_push($this->_stack, $value);
}
public function pop() {
return array_pop($this->_stack);
}
public function isEmpty() {
return empty($this->_stack);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment