PHP cURL API响应处理

I have a question regarding the handling of a response from an API using the cURL function from PHP. If I access the API via cURL I get the following response:

{"status":"ok","meta":{"count":1},"data":{"502268596":{"clan_id":500022074}}}

I transformed this code (named $json) using:

$jsondecoded = json_decode($json,true);

If I var_dump the associative array I now got I receive the following:

array(3) { ["status"]=> string(2) "ok" ["meta"]=> array(1) { ["count"]=> int(1) } ["data"]=> array(1) { [502268596]=> array(1) { ["clan_id"]=> int(500022074) } } }

My Question is: How do I access the field "clan_id"? I'm absolutely lost, because I don't have a real understanding of how arrays work and how I cycle through them.

Your response data is in array format. In this specific case, you can access clan id as follows:

echo $jsondecoded['data'][502268596]['clan_id'];

If you would rather work with objects, you can do so this way:

$jsondecoded = json_decode($json);
echo $jsondecoded->data->{502268596}->clan_id;