Download the PHP package ayesh/case-insensitive-array without Composer
On this page you can find all versions of the php package ayesh/case-insensitive-array. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ayesh/case-insensitive-array
More information about ayesh/case-insensitive-array
Files in ayesh/case-insensitive-array
Package case-insensitive-array
Short Description Class to store and access data in a case-insensitive fashion, while maintaining the integrity and functionality of a regular array.
License MIT
Homepage https://github.com/Ayesh/CaseInsensitiveArray
Informations about the package case-insensitive-array
Case Insensitive Array
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.
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
- PHP 7.3 or later. For older PHP versions, use please use the
1.1.x
or1.0.x
versions.
Installing
The simplest way would be to install using composer.
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
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.
Iterate
You can iterate the array object using foreach(). The exact key and value will be returned.
You can also iterate the array with the same Iterator methods. For a near-perfect array imitation, what we need is ArrayIterator. 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
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.