container = new ArrayObject (); } function insert ($value, $priority) { $key = $this->getNextKey (); $this->container [$key] = $value; $this->priority [$key] = $priority; } function remove ($item) { $keys = array (); foreach ($this->container as $key => $value) { if ($value === $item) { $keys [] = $key; } } foreach ($keys as $key) { unset ($this->container [$key]); unset ($this->priority [$key]); } } public function getIterator () { return new ArrayIterator ($this->buildSequence ()); } private function getNextKey () { $this->key ++; return $this->key; } private function buildSequence () { $result = array (); $this->sequence = $this->priority; asort ($this->sequence); foreach ($this->sequence as $key => $priority) { $result [] = $this->container [$key]; } return $result; } }