0
$json = <<<'JSON'
{
   "statuscode":"TXN",
   "status":"Transaction Successful",
   "data":{
      "item":[
         {
            "id":"1",
            "zone":"S",
            "state_alias":"AP",
            "state":"ANDHRA PRADESH",
            "is_active":"1"
         },
         {
            "id":"2",
            "zone":"E",
            "state_alias":"AR",
            "state":"ARUNACHAL PRADESH",
            "is_active":"1"
         },
         {
            "id":"3",
            "zone":"E",
            "state_alias":"AS",
            "state":"ASSAM",
            "is_active":"1"
         },
         {
            "id":"4",
            "zone":"E",
            "state_alias":"BR",
            "state":"BIHAR",
            "is_active":"1"
         },
         {
            "id":"5",
            "zone":"W",
            "state_alias":"CG",
            "state":"CHHATTISGARH",
            "is_active":"1"
         },
         {
            "id":"6",
            "zone":"W",
            "state_alias":"GA",
            "state":"GOA",
            "is_active":"1"
         }
      ]
   }
}
JSON;

$json_data  = json_decode($json, true);

foreach($json_data['data'] as $r){

    foreach($r['item'] as $data){

       echo $data->id;

    }               

}

I need to list out all the states in loop.

smarber
  • 4,829
  • 7
  • 37
  • 78
Dillip
  • 21
  • 5

0 Answers0