Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 views
in Technique[技术] by (71.8m points)

PHP array, Are array indexes case sensitive?

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.

question from:https://stackoverflow.com/questions/1511230/php-array-are-array-indexes-case-sensitive

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...