• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

PHP 兑现队列类 仅供参考

php 搞代码 3年前 (2022-01-24) 9次浏览 已收录 0个评论

PHP 实现队列类 仅供参考

<?php/** * PHP Class for queue * @author [email protected] * @copyright DataFrog Beijingbei  Ltd. 2011-07-25 */class Queue {	public  $length=12;	public  $queue  = array();  //  if String like this "22,23,24"    convert to array to do queue	public  $delimiter=',';	function __construct($queue=array())	{		$this->queue=$queue;	}		/**	 * @desc start queue	 * @param String  $param  new queue element	 */	public function run($param)	{		if(!is_array($this->queue)){			$this->strToQue();		}		$currentlength=$this->countqueue();  //Count  the  queue length		if($currentlengthlength&&$this->length>0) {			$this->queAdd($param);		}else if($this->length=0)		{			$this->queue[]=$param;		}		else {			$this->queRemove();			$this->queAdd($param);		}					return $this->queue;				}	/**	 * String like this "22,23,24"  convert to array to do queue	 *<p style="color:transparent">本文来源gao!%daima.com搞$代*!码$网3</p><strong>搞代gaodaima码</strong> @param String $string	 * @param String $delimiter	 */	public function strToQue (){		if (empty($this->queue))		{			$this->queue=array();		}		else 		{		$this->queue=explode($this->delimiter,$this->queue);		}		 				}	/**	 * insert $node into queue	 * @param string $node	 */	private function queAdd($node){		 		array_push($this->queue,$node);		$this->countqueue();	}	private function queRemove(){		$node = array_shift($this->queue);		$this->countqueue();		return $node;	}	private function countqueue(){		$currentlength= count($this->queue);		return $currentlength;	}	function __destruct()	{		unset($this->queue);	}}//example $str='' ;            //array();$obj=new Queue ($str);$obj->length=8;  // 队列元素长度 $obj->delimiter='|';  //如果队列是字符串,则元素直接的分隔符为|$a=$obj->run('91');   //要添加到队列中的元素$a=$obj->run('92'); $a=$obj->run('93'); $a=$obj->run('94'); print_r($a); ?>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP 兑现队列类 仅供参考
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址