PHPackages                             ayesh/case-insensitive-array - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ayesh/case-insensitive-array

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ayesh/case-insensitive-array
============================

Class to store and access data in a case-insensitive fashion, while maintaining the integrity and functionality of a regular array.

v1.5.0(4y ago)1020.7k↓100%22MITPHPPHP ^8.1

Since Nov 23Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Ayesh/case-insensitive-array)[ Packagist](https://packagist.org/packages/ayesh/case-insensitive-array)[ Docs](https://github.com/Ayesh/CaseInsensitiveArray)[ RSS](/packages/ayesh-case-insensitive-array/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (18)Used By (2)

Case Insensitive Array
======================

[](#case-insensitive-array)

[![Latest Stable Version](https://camo.githubusercontent.com/648c3dbd2e2e4ed91ea60dcd1f591a2e5da3b323fe6395dae84a071ae91d3e3b/68747470733a2f2f706f7365722e707567782e6f72672f61796573682f636173652d696e73656e7369746976652d61727261792f762f737461626c65)](https://packagist.org/packages/ayesh/case-insensitive-array) [![GitHub license](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://raw.githubusercontent.com/Ayesh/case-insensitive-array/master/LICENSE) [![CI](https://github.com/Ayesh/case-insensitive-array/workflows/CI/badge.svg)](https://github.com/Ayesh/case-insensitive-array/workflows/CI/badge.svg) [![codecov](https://camo.githubusercontent.com/b292c210856a46cec1f13c98ae5909bdea1dd5b8b31a5a0d8a13c95520717333/68747470733a2f2f636f6465636f762e696f2f67682f41796573682f636173652d696e73656e7369746976652d61727261792f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/Ayesh/case-insensitive-array) [![SensioLabsInsight](https://camo.githubusercontent.com/cd06dde0fcbed161db4957d28503747b220315b514aaf231a156ad4f9235e84d/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f63376265393462352d393631642d343338652d396565622d6463333463393738373031662f6d696e692e706e67)](https://insight.sensiolabs.com/projects/c7be94b5-961d-438e-9eeb-dc34c978701f) [![PHP versions](https://camo.githubusercontent.com/2f4d3ef47cf0b03455f84aa530490523b2a19b435c55c4e1bd44b1a1c1a5e402/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f253230253545372e332d3838393242462e737667 "PHP versions")](https://camo.githubusercontent.com/2f4d3ef47cf0b03455f84aa530490523b2a19b435c55c4e1bd44b1a1c1a5e402/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f253230253545372e332d3838393242462e737667)

Synopsis
--------

[](#synopsis)

A 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.

For 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.

```
$array = new Ayesh\CaseInsensitiveArray\Strict();
$array['x-frame-options'] = 'DENY';
$array['X-FRAME-options'] = 'SAMEORIGIN';
echo $array['X-Frame-Options']; // 'SAMEORIGIN'
```

From 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.

Prerequisites
-------------

[](#prerequisites)

- PHP 7.3 or later. For older PHP versions, use please use the `1.1.x` or `1.0.x` versions.

Installing
----------

[](#installing)

The simplest way would be to install using [composer](https://getcomposer.org).

```
composer require ayesh/case-insensitive-array

```

If, 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.

Usage
-----

[](#usage)

This class aims to take away the fact that you are using an object. Simply use it as an array.

**Initialize with an array**

This is optional, but if you already have an array that you need to "import", instantiate the class with that array.

```
$source = [
  'x-frame-options' => 'Deny',
  'X-FRAME-OPTIONS' => 'SAMEORIGIN'
];

$array = new Ayesh\CaseInsensitiveArray\Strict($source);
// Your initial array is now indexed. That was optional. You can now set/get values freely, as you would do with a regular array.
echo $array['X-Frame-OPTIONS']; // 'SAMEORIGIN'
echo $array['X-FRAME-opTIONS']; // 'SAMEORIGIN'
unset($array['x-frame-options']);
var_dump(isset($array['X-Frame-Options'])); // false
```

**Iterate**

You can iterate the array object using foreach(). The exact key and value will be returned.

```
$array = new Ayesh\CaseInsensitiveArray\Strict($source);
$array['x-frame-options'] = 'SameOrigin';
$array['X-Frame-Options'] = 'Deny'; // Notice the Came Case here.
$array['Strict-Transport-Security'] = 'max-age=31536000; includeSubDomains; preload';
foreach ($array as $key => $value) {
  echo "{$key}: {$value}\r\n";
}
// Output (notice how the case is preserved in X-Frame-Options):
// X-Frame-Options: Deny
// Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
```

You 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.

Development and tests
---------------------

[](#development-and-tests)

All 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.

Credits
-------

[](#credits)

By [Ayesh Karunaratne](https://ayesh.me).

###  Health Score

40

—

FairBetter than 87% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 97.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~115 days

Recently: every ~134 days

Total

17

Last Release

1616d ago

PHP version history (5 changes)1.0.0PHP ^5.6 || ^7.0

v1.1.0PHP ^7.2

v1.2.0PHP ^7.3

v1.4.0PHP ^7.3 || ^8.0

v1.5.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/1703f88c1f225e3fadff28458e81328f86668d9631a8c489f45ea1aaebe12df2?d=identicon)[Ayesh](/maintainers/Ayesh)

---

Top Contributors

[![Ayesh](https://avatars.githubusercontent.com/u/811553?v=4)](https://github.com/Ayesh "Ayesh (81 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")

---

Tags

iteratorphpphp-arrayarrayiteratorarray-accessArrayAccesscase insensitive

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ayesh-case-insensitive-array/health.svg)

```
[![Health](https://phpackages.com/badges/ayesh-case-insensitive-array/health.svg)](https://phpackages.com/packages/ayesh-case-insensitive-array)
```

###  Alternatives

[athari/yalinqo

YaLinqo, a LINQ-to-objects library for PHP

4561.2M5](/packages/athari-yalinqo)[ginq/ginq

LINQ to Object inspired DSL for PHP

192257.5k3](/packages/ginq-ginq)[rotexsoft/versatile-collections

A collection package that can be extended to implement things such as a Dependency Injection Container, RecordSet objects for housing database records, a bag of http cookies, or technically any collection of items that can be looped over and whose items can each be accessed using array-access syntax or object property syntax.

186.0k1](/packages/rotexsoft-versatile-collections)[malarzm/collections

Various implementations of Doctrine's Collection interface

2368.1k](/packages/malarzm-collections)[chdemko/bitarray

BitArray for PHP &gt;= 8.2

1116.2k](/packages/chdemko-bitarray)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
