Skip to content

Instantly share code, notes, and snippets.

@meetrajesh
Created May 29, 2012 16:55
Show Gist options
  • Save meetrajesh/2829512 to your computer and use it in GitHub Desktop.
Save meetrajesh/2829512 to your computer and use it in GitHub Desktop.
The Simplest Implementation of a PHP Stack
class stack {
private $arr = array();
public function push($s) {
$this->arr[] = $s;
}
public function pop() {
return array_pop($this->arr);
}
public function peek() {
return end(array_values($this->arr));
}
public function isempty() {
return empty($this->arr);
}
}
@physhik
Copy link

physhik commented Feb 2, 2019

Hi,
I think that
return end(array_values($this->arr));
should be fixed to
end($this->arr);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment