0

I have this json file

{
"success": true,
"data": {
    "total": "2",
    "returned": 2,
    "start": 0,
    "limit": 10,
    "transactions": [
        {
            "id": "16393567",
            "type": "Credit",
            "currency": "BTC",
            "amount": "0.00019449",
            "when": "2021-09-03 10:27:48",
            "rental": "3411209",
            "rig": "205363",
            "status": "Pending",
            "pending_seconds": "716202"
        },
        {
            "id": "16377905",
            "type": "Credit",
            "currency": "BTC",
            "amount": "0.00000203",
            "when": "2021-09-01 11:42:47",
            "rental": "3408621",
            "rig": "205363",
            "status": "Cleared",
            "pending_seconds": 0
        }
    ]
}

}

I am able to get values under data with this code

 $jsonCont = file_get_contents('temp.json');    
 $content = json_decode($jsonCont, true);

 $rig_detail= $content['data']['total'];
 $rig_detail= $content['data']['returned'];
 $rig_detail= $content['data']['start'];
 $rig_detail= $content['data']['limit'];

My problem exists where I try and get data from "transactions" I have tried

 $rig_detail= $content['data']['transactions']['id'];

This however does not give me what I expected. What do I need to do to access the data within the transactions section?

1 Answers1

1

the are more elements in $content['data']['transactions'], so it is an array.

Try something like this:

 $rig_detail= $content['data']['transactions'][0]['id'];
Erwin Moller
  • 2,375
  • 14
  • 22