I have this JSON object:
$json = '{
"droplet":{
"id":3286068,
"name":"some.domain.com",
"memory":512,
"vcpus":1,
"disk":20,
"locked":false,
"status":"active",
"kernel":{
"id":377,
"name":"CentOS 6.5 x64 vmlinuz-2.6.32-431.1.2.0.1.el6.x86_64",
"version":"2.6.32-431.1.2.0.1.el6.x86_64"
},
"created_at":"2014-11-25T19:54:41Z",
"features":[
"virtio"
],
"backup_ids":[
],
"next_backup_window":null,
"snapshot_ids":[
8724513
],
"image":{
"id":8385856,
"name":"rr1.2",
"distribution":"CentOS",
"slug":null,
"public":false,
"regions":[
"nyc2",
"nyc2"
],
"created_at":"2014-12-25T19:09:02Z",
"min_disk_size":20
},
"size_slug":"512mb",
"networks":{
"v4":[
{
"ip_address":"104.131.211.202",
"netmask":"255.255.224.0",
"gateway":"104.131.192.1",
"type":"public"
}
],
"v6":[
]
},
"region":{
"name":"New York 2",
"slug":"nyc2",
"sizes":[
],
"features":[
"virtio",
"private_networking",
"backups"
],
"available":null
}
}
}';
I can run this:
$arr = json_decode($json);
echo "{$arr->droplet->id}";
and echo out the id just fine. But I have been trying 2 hours to echo the ip_address that is deeper in the JSON object...
How do I echo the ip_address and nothing but the ip_address?
P.S. Please don't show me how to do this with a regex. I can do it that way. I want to learn how to echo "ip_address" in the same way I'm echo'ing the "id".
var_dump($arr)to see what the structure is. probably it's not decoding to an object, just a plain php array.