我有以下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