duanlian1320 2015-04-12 07:48
浏览 34

奇怪的关联数组

At the moment I got very weird bug in PHP related with Associative Array, here the chunk of code:

$value="Hello World";
echo $value['randomassocname'];

Why it always return the first character which is "H" even though there's no assoc array attached ? how to fix this problem ?

  • 写回答

1条回答 默认 最新

  • dqwh1203 2015-04-12 07:50
    关注

    This is not a bug! If you have error reporting on:

    <?php
        ini_set("display_errors", 1);
        error_reporting(E_ALL);
    ?> 
    

    You would get this error:

    Warning: Illegal string offset 'randomassocname'

    So because you have that off you don't see the error and randomassocname gets implicit casted to an integer here 0 and it access the first character of the string

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line