-2

I have sample json data as below

[{"@attributes":{"id":"F11D-6T47"},"Name":{"FirstName":"Praveen",
"MiddleName":{},"LastName":"Indukuri","NameSuffix":{}},
"DateOfBirth":{"Day":"31","Month":"08","Year":"1990"},"Phone":"4047549241",
"SSN":"670249778","DriversLicenseNumber":"I532671903110",
"Address":{"Line1":"144 Towey Trai","Line2":{},"Line3":{},
"City":"Woodstock","State":"Georgia","Zip":"30188","County":{},
"Latitude":"0","Longitude":"0"}},{"@attributes":{"id":"F11D-6T47"},
"Name":{"FirstName":"Praveen","MiddleName":{},"LastName":"Indukuri",
"NameSuffix":{}},"DateOfBirth":{"Day":"31","Month":"08","Year":"1990"},
"Phone":"4047549241","SSN":"670249778","DriversLicenseNumber":"I532671903110",
"Address":{"Line1":"144 Towey Trai","Line2":{},"Line3":{},
"City":"Woodstock","State":"Georgia","Zip":"30188",
"County":{},"Latitude":"0","Longitude":"0"}}]

I want to get all the id valued in @attributes for the enitre array using php.

mort
  • 12,988
  • 14
  • 52
  • 97
Sowmya Vejerla
  • 93
  • 1
  • 15

1 Answers1

0

Assign your json to a variable let's say $json and decode it to get a php array.

$array = json_decode($json, true);
// array to store the ids.
$ids = array();
foreach($array as $item) {
   $attributes = $item['@attributes'];
   array_push($ids, $attributes['id']);
}

Hope this helps.

Mubashar Abbas
  • 5,536
  • 4
  • 38
  • 49