Home  >  Article  >  Backend Development  >  PHP中的array数组类型分析说明_PHP

PHP中的array数组类型分析说明_PHP

WBOY
WBOYOriginal
2016-06-01 12:17:56908browse

php的数组的key 可以是string类型也可以是integer类型。如果key为一个float类型,会自动的转化为integer类型。

如果没有为一个value指定一个key,integer类型的索引的最大值已经给出的话,新key就是这个最大值加1.如果这个新key已经被赋值,那么这个value将会被覆盖掉。
复制代码 代码如下:
$arr = array('a','b',5=>'c','d','e',6=>'g');
echo '

'; <br>print_r($arr); <br>echo '
';


上面代码的结果是

复制代码 代码如下:
Array(
[0] => a
[1] => b
[5] => c
[6] => g
[7] => e)


这个样子。只所以没有value “d” 是因为 他被后面的6=>‘g'这个给覆盖掉了
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn