栈
<?php class Stack{ public static $dataInfo = array(); public static $theMax= 10; public static $length=0; // public static $stackInfo; public function addData($data){ if(self::$length >= self::$theMax){ return false; }else{ array_push(self::$dataInfo,$data); self::$length ++; } } public function outData(){ if(self::$length<=0 ){ return false; }else{ $data = array_pop(self::$dataInfo); self::$length --; return $data; } } public function getAll(){ foreach (self::$dataInfo as $value) { // code.. print_r($value); } } } $a = new Stack(); $a->addData(1); $a->addData(3); $a->addData(5); $a->getAll(); print_r($a->outData()); ?>
同理,队列也是一样的 只不过可以把array_pop()换成array_shift()。