Created
May 29, 2012 16:55
-
-
Save meetrajesh/2829512 to your computer and use it in GitHub Desktop.
The Simplest Implementation of a PHP Stack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I think that
return end(array_values($this->arr));
should be fixed to
end($this->arr);