Skip to content

Latest commit

 

History

History
36 lines (25 loc) · 840 Bytes

File metadata and controls

36 lines (25 loc) · 840 Bytes

CaseInsensitiveArray

Associative arrays with case insensitive keys for PHP

This is a convenient single-class version compiled from the more abstract CustomHashArray

Usage

$arr = new CaseInsensitiveArray;
$arr['HelloWorld'] = 'hi';

echo $arr['helloworld'];
// Outputs: hi

$arr['other'] = 'Other thing';
$arr['helloWorld'] = 'Same key';

foreach ($arr as $key => $value) {
    echo $key.' => '.$value."\n";
}
// Outputs:
//   other => Other thing
//   helloWorld => Same key

Behaviour

Key access is case insensitive. When accessing the array's keys they will be returned as the original case that defined them.

If an existing key is overwritten with a different case the new case will be used when returning key names.