0

I set up a new site and want a workaround for the problem. I have this text in the mysql table

{"200":"5","220":"0","65":"4","80":"0","199":"1","197":"1","198":"0","257":"4","223":"0"}

I want to fetch the ID and its value by php For example

$id[200] = 5
Zain Farooq
  • 2,956
  • 3
  • 20
  • 42

1 Answers1

0

You can use json_decode() to convert JSON string into an array. Since your JSON string contains numeric indexes so you need to use curly brackets to fetch the values

$str = '{"200":"5","220":"0","65":"4","80":"0","199":"1","197":"1","198":"0","257":"4","223":"0"}';
$array = json_decode($str);
echo $array->{'200'};

Or you can add second parameter in json_decode as true to fetch the value as normal array

$array = json_decode($str,true);
echo $array[200];

Here is the live demo

Zain Farooq
  • 2,956
  • 3
  • 20
  • 42
  • or add `true` as second param for `json_decode` and use output as normal array with numeric keys. – Pyton May 24 '19 at 06:55