class DoubleQueue{
private $_queue=array();
public function __construct()
{
}
/**
* 得到数组的总大小
*/
public function count()
{
return count($this->_queue);
}
/**
* 将一个单元压入数组尾部
*/
public function queuePush($data)
{
return array_push($this->_queue,$data);
}
/**
*将一个单元压入数组开头
*/
public function queueUnshift($data)
{
return array_unshift($this->_queue,$data);
}
/**
* 从数组最后一个移出
*/
public function queuePop()
{
if($this->count()<=0){
return false;
}
return array_pop($this->_queue);
}
/**
* 将数组中的第一个单元移出
*/
public function queueShift()
{
if($this->count()<=0){
return false;
}
return array_shift($this->_queue);
}
/**
* 清空队列
*/
public function queueEmpty()
{
return unserialize($this->_queue);
}
/**
* 查找某个值是否在队列中
* @param 要查找的值
*/
public function queueExist($data)
{
if( !is_array($data) && $this->count() >= 1 ) {
return in_array($data,$this->_queue);
} else {
return false;
}
}
/**
* 得到某个索引的value
* @param $index 索引
*/
public function getIndexQueue($index)
{
if( is_numeric($index) && $this->count() >= 1) {
return $this->_queue[$index];
} else {
return false;
}
}
}