PHP cash queue class for reference only

Source: Internet
Author: User
PHP implements the queue class for reference only & lt ;? Php/*** PHPClassforqueue * @ authoryangqijun@live.cn * @ copyrightDataFrogBeijingbeiLtd.2011 PHP queue class for reference only
 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 $ del Imiter */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 cou Ntqueue () {$ currentlength = count ($ this-> queue); return $ currentlength;} function _ destruct () {unset ($ this-> queue );}} // example $ str = ''; // array (); $ obj = new Queue ($ str); $ obj-> length = 8; // queue element length $ obj-> delimiter = '|'; // if the queue is a string, the separator of the element is | $ a = $ obj-> run ('91 '); // elements to be added to the queue $ a = $ obj-> run ('92 '); $ a = $ obj-> run ('93 '); $ a = $ obj-> run ('94 '); print_r ($ a);?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.