PHP array, Are array indexes case sensitive?

Phill Pafford picture Phill Pafford · Oct 2, 2009 · Viewed 13.9k times · Source

I don't know if this is a problem yet but wanted to start thinking about it.

Question:

"Are PHP array indexes case sensitive"?

Example:

$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse","A"=>"Dog","B"=>"Cat","C"=>"Horse");
print_r($a);

Results:

Array ( [a] => Dog [b] => Cat [c] => Horse [A] => Dog [B] => Cat [C] => Horse ) 

I've run a couple of examples and this seems to hold true, just wanted to make sure that I'm seeing this correctly.

Answer

Dan Herbert picture Dan Herbert · Oct 2, 2009

Yes. They are case sensitive.

PHP array indexes act as hash tables in your example. A capital letter "A" and a lowercase letter "a" have different hash values, therefore they will be different indexes.