return false; } } function First() { return $this->stackArray[$this->index]; } function Last() { return $this->stackArray[0]; } public function getElement($position) { if ($position <= $this->index + 1) { $arrayPosition = $this->index + 1 - $position; return $this->stackArray[$arrayPosition]; } else { echo "Invalid"; } } } $myStack = new Stack(); $myStack->push(1); $myStack->push(4); $myStack->push(5); echo "First pop is ", $myStack->pop(), "<br>"; echo "Second pop is ", $myStack->pop(), "<br>"; echo "First value of stack is ", $myStack->First(), "<br>"; $myStack->pop(); echo "present index value is ", $myStack->getElement(2);
echo "stack is empty"; } } public function isEmpty() { if ($this->index == -1) { return true; } else { return false; } } public function first() { echo $this->stackArray[$this->index]; } public function last() { echo $this->stackArray[0]; } } $newStack = new Stack(); $newStack->push(2); $newStack->push(6); $newStack->pop(); $newStack->pop(); $newStack->pop(); $newStack->isEmpty(); $newStack->first(); $newStack->last(); $newStack->getElement(1);