不合逻辑的“未定义偏移量”!

时间:2017-05-25 23:31:41

标签: php

这是我的调试代码:

        echo $val2[ $key ];
        echo $val2[ 0 ];
        echo $val2[ "0" ];
        var_dump( $val2 );
        die();

这是输出:

Notice: Undefined offset: 0 in index.php on line 319

Notice: Undefined offset: 0 in index.php on line 320

Notice: Undefined offset: 0 in index.php on line 321
array(1) { ["0"]=> float(0.123)  }

这让我发疯了,为什么说明显没有钥匙?

1 个答案:

答案 0 :(得分:0)

问题来自

$val2 = (array) json_decode( $data );

应该是:

$val2 = json_decode( $data, true );