PHP数组,是数组索引区分大小写? [英] PHP array, Are array indexes case sensitive?

查看:178
本文介绍了PHP数组,是数组索引区分大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这是否是一个问题,不过也想开始思考它。

问:

是PHP数组索引区分大小写

例如:

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

结果:

 阵列([A] =&GT;狗[B] =&GT;猫[C] =&GT;马[A] =&GT;狗[B] =&GT;猫[ J] =&GT;马)

我已经运行几个例子,这似乎是正确的,只是想确保我正确地看到这一点。


解决方案

是的。他们是区分大小写的。

PHP数组索引作为哈希表在你的榜样的。大写字母A和小写字母a有不同的哈希值,因此它们将不同的索引。

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.

解决方案

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.

这篇关于PHP数组,是数组索引区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆