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);?>