/**
* PHP类实现队列功能
*/
class ListPhp
{
protected $query = [];
/**
* [addLeft description]在数组头部添加一个或多个元素
* @param [type] $item [description]
*/
public function addLeft($item)
{
return array_unshift($this->query, $item);
}
/**
* 将一个或多个元素追加到数组尾部
* @param [type] $item [description]
*/
public function addRight($item)
{
return array_push($this->query,$item);
}
/**
* 从数组开头弹出一个或多个元素
* @return [type] [description]
*/
public function removeLeft()
{
return array_shift($this->query);
}
/**
* 从数组末尾弹出元素
* @return [type] [description]
*/
public function removeRight()
{
return array_pop($this->query);
}
public function getList()
{
return $this->query;
}
}
echo '<hr />';
$listPhp = new listPhp();
$listPhp->addLeft('hello');
$listPhp->addRight('world');
$listPhp->addLeft('admin');
print_r($listPhp->getList());
PHP实现队列
最新推荐文章于 2024-03-22 16:40:13 发布