keys = []; $this->fields = []; $this->values = []; } // ------------------------------------------------------------------------ // ArrayAccess /** * @param string $offset * @return bool */ public function offsetExists($offset) { return isset($this->values[strtolower($offset)]); } /** * @param mixed $offset * @return string[] */ public function offsetGet($offset) { return $this->values[strtolower($offset)]; } /** * @param string $offset * @param string $value */ public function offsetSet($offset, $value) { $normalized = strtolower($offset); // Add the normalized key to the list of keys, if not already set. if (!in_array($normalized, $this->keys)) { $this->keys[] = $normalized; } // Add or update the preserved case key. $this->fields[$normalized] = $offset; // Store the value. if (isset($this->values[$normalized])) { $this->values[$normalized][] = $value; } else { $this->values[$normalized] = [$value]; } } /** * @param string $offset */ public function offsetUnset($offset) { $normalized = strtolower($offset); unset($this->fields[$normalized]); unset($this->values[$normalized]); // Remove and normalize the list of keys. if (($key = array_search($normalized, $this->keys)) !== false) { unset($this->keys[$key]); $this->keys = array_values($this->keys); } } // ------------------------------------------------------------------------ // Iterator public function current() { return $this->values[$this->keys[$this->position]]; } public function next() { ++$this->position; } public function key() { return $this->fields[$this->keys[$this->position]]; } public function valid() { return isset($this->keys[$this->position]); } public function rewind() { $this->position = 0; } }