PHP array, Are array indexes case sensitive?

☆樱花仙子☆ 提交于 2019-12-17 11:17:32

问题


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.


回答1:


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.




回答2:


Answer:

Yes, they are.




回答3:


Yes, just like variable names (but not function names), hash keys are case-sensitive.




回答4:


That's easy enough to check on your own.

$dogs = array('Dog' => 'Wuff', 'dog' => 'wuff', 'DOG' => 'WUFF');
var_dump($dogs);



回答5:


Although it's not true of the system with which most people are familiar (Windows), it's a reasonable assumption to make when approaching any new language or environment that it will be case sensitive. PHP is along with virtually every other language and environment in common use. The most notable exceptions that spring to mind (apart from the aforementioned Windows) are SQL and Delphi (Pascal).




回答6:


just like everyone else mentioned, "Yes They Are".

fore example $a['id'] is different with $a['ID']



来源:https://stackoverflow.com/questions/1511230/php-array-are-array-indexes-case-sensitive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!