DEM
DEM

Reputation: 333

How to access 'Final Balance

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

Answers (3)

Eliâ Melfior
Eliâ Melfior

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

Madhur Bhaiya
Madhur Bhaiya

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

Lawrence Cherone
Lawrence Cherone

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

Related Questions