Reputation: 333
After Json Decode how do I access the 'final_balance' value ?
Array ( [19BCZwWvYVh5yRLgdT6Yicnou8iYy7TUaS] => Array ( [final_balance] => 154014 [n_tx] => 1 [total_received] => 154014 ) )Ive tried this
$json1a = json_decode(file_get_contents($url1a), true);
$balance1 = $json1a[0]['final_balance'];
echo $balance1;
but no go, thanks
Upvotes: 1
Views: 50
Reputation: 369
$json1a = json_decode(file_get_contents($url1a), true);
$json1a = array_values($json1a);
$balance1 = $json1a[0]['final_balance'];
echo $balance1;
Edited, following Lawrence Cherone's answer.
Upvotes: 1
Reputation: 28864
If you don't know the key, you can fetch the first key from the array:
$json1a = json_decode(file_get_contents($url1a), true);
$balance1 = $json1a[key($json1a)]['final_balance'];
echo $balance1;
Upvotes: 0
Reputation: 46630
If you don't know the key before-hand use array_values()
$json1a = array_values($json1a);
echo $json1a[0]['final_balance'];
Upvotes: 3