0

I have one problem here. I'm using file as cache for storing MySQL result. Here are the results inside the cache file:

[
   {
      "Name":"Bell",
      "Class":"BWB0",
      "Lv":31,
      "Kill":0,
      "Serial":3,
      "PvpPoint":0,
      "Death":0
   },
   {
      "Name":"Perkss",
      "Class":"AWB0",
      "Lv":17,
      "Kill":0,
      "Serial":6,
      "PvpPoint":2400,
      "Death":0
   },
   {
      "Name":"1233",
      "Class":"BWB0",
      "Lv":3,
      "Kill":0,
      "Serial":1,
      "PvpPoint":0,
      "Death":0
   },
   {
      "Name":"Cora",
      "Class":"CWB0",
      "Lv":1,
      "Kill":0,
      "Serial":4,
      "PvpPoint":0,
      "Death":0
   }
]

Any idea to convert the result cache file into usual output ? like "echo $row['Name']".

Thanks, I'm just a newbie want to learn PHP :)

Tharindu
  • 339
  • 6
  • 19
  • 1
    Possible duplicate of [How do I extract data from JSON with PHP?](https://stackoverflow.com/questions/29308898/how-do-i-extract-data-from-json-with-php) – M. Eriksson Oct 11 '18 at 05:50

1 Answers1

0
$json_string = '[{"Name":"Bell","Class":"BWB0","Lv":31,"Kill":0,"Serial":3,"PvpPoint":0,"Death":0},{"Name":"Perkss","Class":"AWB0","Lv":17,"Kill":0,"Serial":6,"PvpPoint":2400,"Death":0},{"Name":"1233","Class":"BWB0","Lv":3,"Kill":0,"Serial":1,"PvpPoint":0,"Death":0},{"Name":"Cora","Class":"CWB0","Lv":1,"Kill":0,"Serial":4,"PvpPoint":0,"Death":0}]';
$a = json_decode($json_string, true);

foreach($a as $row)
    {
    echo $row['Name'];
    }
Rubin Porwal
  • 3,736
  • 1
  • 23
  • 26
  • This question has been asked and answered on SO many times before. Let's keep the site clean from duplicates by closing it as one instead of answering with yet another example. – M. Eriksson Oct 11 '18 at 06:05
  • Sorry, i just don't know what function is this. That's why im asking. – Aprilio Oct 11 '18 at 06:14