function stack() { // class constructor
$this->size = 0;
unset($this->arrays);
}
function push($elem) { // put an element on stack
$this->arrays[$this->size] = $elem;
$this->size++;
}
function get_size() { // get number of elements stored
return $this->size;
}
function is_empty() { // is stack empty ?
return ($this->size == 0) ? true : false;
}
function pop() { // retrieve an element from the top of stack
if ( $this->is_empty() == false ) {
$this->size--;
return $this->arrays[$this->size];
}
else
return 0;
}
}
$inst = new stack; // create an object from stack class
echo "initial stack size=".($inst->get_size()),"<BR>\n";