PHP数组,数组索引区分大小写吗?

发布于 2024-08-06 17:12:13 字数 414 浏览 7 评论 0原文

我不知道这是否是一个问题,但想开始考虑它。

问题:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

凝望流年 2024-08-13 17:12:13

是的。它们区分大小写。

在您的示例中,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.

岁月静好 2024-08-13 17:12:13

回答:

是的,是的。

Answer:

Yes, they are.

眼中杀气 2024-08-13 17:12:13

是的,就像变量名(但不是函数名)一样,哈希键区分大小写。

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

他夏了夏天 2024-08-13 17:12:13

这很容易你自己检查一下。

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

That's easy enough to check on your own.

$dogs = array('Dog' => 'Wuff', 'dog' => 'wuff', 'DOG' => 'WUFF');
var_dump($dogs);
此岸叶落 2024-08-13 17:12:13

尽管大多数人熟悉的系统(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).

粉红×色少女 2024-08-13 17:12:13

就像其他人提到的那样,“是的,他们是”。

例如 $a['id'] 与 $a['ID'] 不同

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文