Skip to end of metadata
Go to start of metadata

To implement Queue, the easiest way can do it is using array() to store elements, and array_shift() to extract elements at the front of the Queue.

Below is a simple class for Queue.

<?php

class TQueue {

 protected $_storage = array();

 public function add( $item ) {
  $this->_storage[] = $item;
 }

 function get() {
  return array_shift($this->_storage);
 }

};


Below is a simple example to add text strings, and get until empty:

<?php

class TQueue {

 protected $_storage = array();

 public function add( $item ) {
  $this->_storage[] = $item;
 }

 function get() {
  return array_shift($this->_storage);
 }

};

$q = new TQueue;

$q->add( "hello");
$q->add( "world");

while(1)
{
        $v = $q->get();
        if (!$v) break;
        echo $v . "\n";
}

?>