开发者社区 问答 正文

求助一个关于PHP数组的问题

$a[3] = 5;
$a["3"] = 6;
$a["3.14"] = 7;
$a[3.14] = 8;

echo $a[3], $a["3"], $a["3.14"], $a[3.14];

输出为什么是 8878?

展开
收起
落地花开啦 2016-06-13 15:32:22 1846 分享 版权
1 条回答
写回答
取消 提交回答
  • 喜欢技术,喜欢努力的人

    Additionally the following key casts will occur:
    screenshot
    screenshotin you case, the 3.14
    screenshot
    `$a[3] = 5;
    $a["3"] = 6;`
    both are same thing and will be cast to $a[3].
    screenshot
    $a["3.14"] = 7; //"3.14" is a string and it won't be cast.
    Summary:
    `$a[3] = 5;
    $a["3"] = 6; // $a[3] is 6 now.
    $a["3.14"] = 7; //"3.14" is a string, no cast then.
    $a[3.14] = 8; // 3.14 will be cast to 3 which results in $a[3] = 8
    echo $a[3], $a["3"], $a["3.14"], $a[3.14];
    is actually
    echo $a[3],$a[3],$a["3.14"],$a[3]`
    都用引号

    2019-07-17 19:36:10
    赞同 展开评论
问答分类:
PHP
问答标签:
问答地址: