小编sha*_*r s的帖子

数字Json解码不起作用

我有以下json代码

 {"1":1,"5":1}
Run Code Online (Sandbox Code Playgroud)

当我解码上面的json时,我使用下面的php语句得到了对象数组.

$array_val = (array)json_decode($price);
Run Code Online (Sandbox Code Playgroud)

我有一个下面的数组.

Array
(
  [1] => 1
  [5] => 1
)
Run Code Online (Sandbox Code Playgroud)

但以下声明不起作用

echo $array_val[1];
Run Code Online (Sandbox Code Playgroud)

发生以下错误.
未定义的偏移量:1

如何解决这个问题?

php

1
推荐指数
1
解决办法
123
查看次数

标签 统计

php ×1