-1

I am new to php. I trying to get value from json object. I tried many time but i failed to get value from json. I need only "txnToken" from json array. My code is

$json = json_decode($data, true);
foreach ($json as $key => $value) {
    foreach ($value as $key1 => $value1) {
           print_r($key1);
           
    }
}

And JSON Response is:

{
    "head": {
        "responseTimestamp":"1596640639585",
        "version":"v1",
        "clientId":"WEB",
        "signature":"xxxxxxxxxxxxxxxx"
    },
    "body":{
        "resultInfo":{
            "resultStatus":"S",
            "resultCode":"0000",
            "resultMsg":"Success"
        },
        "txnToken":"xxxxxxxxxxxxx",
        "isPromoCodeValid":false,
        "authenticated":false
    }
}

Thanks in advance.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Sutanu Rath
  • 131
  • 1
  • 6

2 Answers2

2

I guess it should be as easy as this:

$json = json_decode($data, true);
print_r($json['body']['txnToken']);
1

Does it work if you do

$json['body']['txnToken']
mark_b
  • 1,393
  • 10
  • 18