WC_Eval_Math_Stack

Class WC_Eval_Math_Stack.


Description Description


Source Source

File: includes/libraries/class-wc-eval-math.php

	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;
		}
	}

Top ↑

Methods Methods

  • last — Get last value from stack.
  • pop — Pop value from stack.
  • push — Push value into stack.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.