Skip to content

Instantly share code, notes, and snippets.

@zachflower
Last active August 24, 2016 13:24
Show Gist options
  • Save zachflower/7fe5f231a56761b4f73a to your computer and use it in GitHub Desktop.
Save zachflower/7fe5f231a56761b4f73a 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