shanmugakumar s shanmugakumar s - 1 year ago 136
PHP Question

numeric Json decode not work

i have below json code


when i decode the above json i got object array using the below php statement.

$array_val = (array)json_decode($price);

i got a below array.

[1] => 1
[5] => 1

but the below statement does not work

echo $array_val[1];

the below error occurred.

Undefined offset: 1

How to resolve this issue?

Answer Source

try this DEMO


$json = '{"1":1,"5":1}';
$array_val=json_decode($price, true);
echo $array_val[1];


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download