WC_Eval_Math_Stack{}WC 1.0

Class WC_Eval_Math_Stack.

No Hooks.

Usage

$WC_Eval_Math_Stack = new WC_Eval_Math_Stack();
// use class methods

Methods

  1. public last( $n=1 )
  2. public pop()
  3. public push( $val )

WC_Eval_Math_Stack{} code WC 9.4.2

class WC_Eval_Math_Stack {

	/**
	 * Stack array.
	 *
	 * @var array
	 */
	public $stack = array();

	/**
	 * Stack counter.
	 *
	 * @var integer
	 */
	public $count = 0;

	/**
	 * Push value into stack.
	 *
	 * @param  mixed $val
	 */
	public function push( $val ) {
		$this->stack[ $this->count ] = $val;
		$this->count++;
	}

	/**
	 * Pop value from stack.
	 *
	 * @return mixed
	 */
	public function pop() {
		if ( $this->count > 0 ) {
			$this->count--;
			return $this->stack[ $this->count ];
		}
		return null;
	}

	/**
	 * Get last value from stack.
	 *
	 * @param  int $n
	 *
	 * @return mixed
	 */
	public function last( $n=1 ) {
		$key = $this->count - $n;
		return array_key_exists( $key, $this->stack ) ? $this->stack[ $key ] : null;
	}
}