{"id":20678671,"url":"https://github.com/ayesh/case-insensitive-array","last_synced_at":"2025-10-25T03:11:57.747Z","repository":{"id":13476088,"uuid":"74471155","full_name":"Ayesh/case-insensitive-array","owner":"Ayesh","description":"A library providing an Array-Class to store and access data in a case-insensitive fashion, while maintaining the integrity and functionality of a regular array.","archived":false,"fork":false,"pushed_at":"2022-05-27T08:47:28.000Z","size":64,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T19:55:51.342Z","etag":null,"topics":["iterator","php","php-array"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ayesh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-22T12:39:27.000Z","updated_at":"2021-12-05T07:13:14.000Z","dependencies_parsed_at":"2022-08-28T05:41:59.142Z","dependency_job_id":null,"html_url":"https://github.com/Ayesh/case-insensitive-array","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ayesh%2Fcase-insensitive-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ayesh%2Fcase-insensitive-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ayesh%2Fcase-insensitive-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ayesh%2Fcase-insensitive-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ayesh","download_url":"https://codeload.github.com/Ayesh/case-insensitive-array/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249820127,"owners_count":21329887,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["iterator","php","php-array"],"created_at":"2024-11-16T21:21:37.946Z","updated_at":"2025-10-25T03:11:52.730Z","avatar_url":"https://github.com/Ayesh.png","language":"PHP","readme":"# Case Insensitive Array\n\n[![Latest Stable Version](https://poser.pugx.org/ayesh/case-insensitive-array/v/stable)](https://packagist.org/packages/ayesh/case-insensitive-array) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/Ayesh/case-insensitive-array/master/LICENSE)  ![CI](https://github.com/Ayesh/case-insensitive-array/workflows/CI/badge.svg) [![codecov](https://codecov.io/gh/Ayesh/case-insensitive-array/branch/master/graph/badge.svg)](https://codecov.io/gh/Ayesh/case-insensitive-array) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/c7be94b5-961d-438e-9eeb-dc34c978701f/mini.png)](https://insight.sensiolabs.com/projects/c7be94b5-961d-438e-9eeb-dc34c978701f)  ![PHP versions](https://img.shields.io/badge/%20%5E7.3-8892BF.svg \"PHP versions\")\n\n## Synopsis\nA class implementing **ArrayAccess**, **Countable**, and **Iterator** interfaces, and allows you to set, get, count, iterate, and validate while enforcing the keys to be case insensitive. \n\nFor example, suppose you have to store a set of HTTP headers. By definition, HTTP headers are case insensitive. With this class, you can peacefully set the same array key-pair combination any number as you feel fit, but the data set will remain consistent. \n\n```php\n$array = new Ayesh\\CaseInsensitiveArray\\Strict();\n$array['x-frame-options'] = 'DENY';\n$array['X-FRAME-options'] = 'SAMEORIGIN';\necho $array['X-Frame-Options']; // 'SAMEORIGIN'\n```\n\nFrom the example above, notice how the array values are set two times with two keys with different case. In the `echo` line, the value is accessed in CamelCase, but you get the same value regardless of your querying keys case. \n\n## Prerequisites\n\n - PHP 7.3 or later. For older PHP versions, use please use the `1.1.x` or `1.0.x` versions.\n\n## Installing\nThe simplest way would be to install using [composer](https://getcomposer.org). \n\n    composer require ayesh/case-insensitive-array\nIf, for some reason, you can't use Composer, or don't want to (Come on!), you can integrate the class with your current `PSR-4` autoloader by mapping `Ayesh\\CaseInsensitiveArray` namespace to the repository's `src` folder. \n\n## Usage\nThis class aims to take away the fact that you are using an object. Simply use it as an array. \n\n**Initialize with an array**\n\nThis is optional, but if you already have an array that you need to \"import\", instantiate the class with that array. \n\n```php\n$source = [\n  'x-frame-options' =\u003e 'Deny',\n  'X-FRAME-OPTIONS' =\u003e 'SAMEORIGIN'\n];\n\n$array = new Ayesh\\CaseInsensitiveArray\\Strict($source);\n// Your initial array is now indexed. That was optional. You can now set/get values freely, as you would do with a regular array.\necho $array['X-Frame-OPTIONS']; // 'SAMEORIGIN'\necho $array['X-FRAME-opTIONS']; // 'SAMEORIGIN'\nunset($array['x-frame-options']);\nvar_dump(isset($array['X-Frame-Options'])); // false\n```\n\n**Iterate**\n\nYou can iterate the array object using foreach(). The exact key and value will be returned. \n\n```php\n$array = new Ayesh\\CaseInsensitiveArray\\Strict($source);\n$array['x-frame-options'] = 'SameOrigin';\n$array['X-Frame-Options'] = 'Deny'; // Notice the Came Case here.\n$array['Strict-Transport-Security'] = 'max-age=31536000; includeSubDomains; preload';\nforeach ($array as $key =\u003e $value) {\n  echo \"{$key}: {$value}\\r\\n\";\n}\n// Output (notice how the case is preserved in X-Frame-Options):\n// X-Frame-Options: Deny\n// Strict-Transport-Security: max-age=31536000; includeSubDomains; preload\n```\n\nYou can also iterate the array with the same [Iterator](http://php.net/manual/en/class.iterator.php) methods. For a near-perfect array imitation, what we need is [ArrayIterator](http://php.net/manual/en/class.arrayiterator.php). However, it is not implemented in the current version. I would gladly work with you if you'd like to help. As of now, my scope is to have 2 classes, Strict and Union that gives basic array access, and `foreach()` compatibility. \n\n## Development and tests\nAll issues are PRs are welcome. Travis CI and PHPUnit tests are included. If you are adding new features, please make sure to add the test coverage.\n\n## Credits\nBy [Ayesh Karunaratne](https://ayesh.me).\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayesh%2Fcase-insensitive-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fayesh%2Fcase-insensitive-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayesh%2Fcase-insensitive-array/lists"}