PHP 兌現隊列類 僅供參考

來源:互聯網
上載者:User
PHP 實現隊列類 僅供參考
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 lengthif($currentlength<$this->length&&$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 * @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); ?>
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.