sourceArray = &$source; array_walk($source, function ($value, $key) { $this->_keyMapping[strtolower($key)] = $key; }); /** * Iterator */ $this->rewind(); } public function offsetSet($offset, $value): void { if (is_null($offset)) { LogUtility::msg("The offset (key) is null and this is not supported"); } else { if (is_string($offset)) { $lowerCaseOffset = strtolower($offset); $this->_keyMapping[$lowerCaseOffset] = $offset; $this->sourceArray[$offset] = $value; } else { LogUtility::msg("The offset should be a string", LogUtility::LVL_MSG_ERROR); } } } public function offsetExists($offset): bool { if (is_string($offset)) $offset = strtolower($offset); return isset($this->_keyMapping[$offset]); } public function offsetUnset($offset): void { if (is_string($offset)) $offset = strtolower($offset); $originalOffset = $this->_keyMapping[$offset] ?? null; unset($this->sourceArray[$originalOffset]); unset($this->_keyMapping[$offset]); } public function offsetGet($offset) { if (is_string($offset)) $offset = strtolower($offset); $sourceOffset = $this->_keyMapping[$offset] ?? null; if ($sourceOffset === null) { return null; } return $this->sourceArray[$sourceOffset] ?? null; } function getOriginalArray(): array { return $this->sourceArray; } public function current() { return $this->iterator->current(); } public function next(): void { $this->iterator->next(); } public function key() { return $this->iterator->key(); } public function valid(): bool { return $this->iterator->valid(); } public function rewind(): void { $obj = new ArrayObject($this->sourceArray); $this->iterator = $obj->getIterator(); } public function count(): int { return sizeof($this->sourceArray); } }