PHP数组,数组索引区分大小写吗?
我不知道这是否是一个问题,但想开始考虑它。
问题:
“PHP 数组索引是否区分大小写”?
示例:
$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse","A"=>"Dog","B"=>"Cat","C"=>"Horse");
print_r($a);
结果:
Array ( [a] => Dog [b] => Cat [c] => Horse [A] => Dog [B] => Cat [C] => Horse )
我运行了几个示例,这似乎是正确的,只是想确保我正确地看到了这一点。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
是的。它们区分大小写。
在您的示例中,PHP 数组索引充当 哈希表。大写字母“A”和小写字母“a”具有不同的哈希值,因此它们将是不同的索引。
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.
回答:
是的,是的。
Answer:
Yes, they are.
是的,就像变量名(但不是函数名)一样,哈希键区分大小写。
Yes, just like variable names (but not function names), hash keys are case-sensitive.
这很容易你自己检查一下。
That's easy enough to check on your own.
尽管大多数人熟悉的系统(Windows)并非如此,但在接触任何新语言或环境时,可以合理地假设它将区分大小写。 PHP 与几乎所有其他常用语言和环境一样。想到的最显着的例外(除了前面提到的 Windows)是 SQL 和 Delphi (Pascal)。
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).
就像其他人提到的那样,“是的,他们是”。
例如 $a['id'] 与 $a['ID'] 不同
just like everyone else mentioned, "Yes They Are".
fore example $a['id'] is different with $a['ID']