$v) will cause errors * if any key is not a string or an integer. * */ class Hash implements ArrayAccess, Iterator, Countable { private $_keys = array(); private $_values = array(); private $_iteratorIndex = 0; public function __construct() { } public function count() { return count($this->_keys); } public function offsetExists($index) { $found = array_search($index, $this->_keys, true); return ($found === false) ? false : true; } public function offsetGet($index) { $valueIndex = array_search($index, $this->_keys, true); if($valueIndex === false) throw new Exception('Undefined offset "'.$index.'"'); return $this->_values[$valueIndex]; } public function offsetSet($index, $value) { $valueIndex = array_search($index, $this->_keys, true); if($valueIndex === false) { $valueIndex = count($this->_keys); $this->_keys[] = $index; } $this->_values[$valueIndex] = $value; } public function offsetUnset($index) { $valueIndex = array_search($index, $this->_keys, true); if($valueIndex === false) return; unset($this->_keys[$valueIndex]); unset($this->_values[$valueIndex]); } public function rewind() { $this->_iteratorIndex = 0; } public function current() { return $this->_values[$this->_iteratorIndex]; } public function key() { return $this->_keys[$this->_iteratorIndex]; } public function next() { $this->_iteratorIndex++; } public function valid() { return !($this->_iteratorIndex >= count($this->_keys)); } }