/** * PHP Class for queue * @author yangqijun@live.cn * @copyright DataFrog Beijingbei Ltd. 2011-07-25 */classQueue {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 */publicfunctionrun($param) {if(!is_array($this->queue)){ $this->strToQue();//將數組視為隊列 } $currentlength=$this->countqueue(); //Count the queue lengthecho$currentlength; echo$this->length.'
'; if($currentlength<$this->length&&$this->length>0) { $this->queAdd($param); }elseif($this->length==0) //如果為空白隊列,則將隊列初始化為輸入的隊列 { $param=empty($param)?0:$param; $this->queue[]=$param; } else { for ($i=0;$i<$currentlength-$this->length-1;$i++)//隊列比規定的隊列多,要刪掉隊首的元素,才能入隊 { $this->queRemove(); } $this->queAdd($param); } return$this->queue; } /** * String like this "22,23,24" convert to array to do queue * @param String $string * @param String $delimiter */publicfunctionstrToQue(){if (empty($this->queue)) { $this->queue=array(); } else { $this->queue=explode($this->delimiter,$this->queue); } } /** * insert $node into queue * @param string $node */privatefunctionqueAdd($node){ array_push($this->queue,$node); $this->countqueue(); } privatefunctionqueRemove(){$node = array_shift($this->queue); $this->countqueue(); return$node; } privatefunctioncountqueue(){$currentlength= count($this->queue); return$currentlength; } function__destruct() {unset($this->queue); } } //example $str='88|89|90|56|23|45|69|23|20|100'; $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);?>
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('
').text(i)); }; $numbering.fadeIn(1700); }); });
以上就介紹了php 隊列類,包括了php,隊列方面的內容,希望對PHP教程有興趣的朋友有所協助。