如何访问'最终余额

问题描述 投票:2回答:3

在Json Decode之后我如何访问'final_balance'值?

    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;

但是没有去,谢谢

php
3个回答
3
投票

如果你不知道密钥前手使用array_values()

$json1a = array_values($json1a);

echo $json1a[0]['final_balance'];

1
投票
$json1a = json_decode(file_get_contents($url1a), true);

$json1a = array_values($json1a);

$balance1 = $json1a[0]['final_balance'];

echo $balance1;

按照劳伦斯·切罗纳的回答编辑。


0
投票

如果您不知道密钥,可以从数组中获取第一个密钥:

$json1a = json_decode(file_get_contents($url1a), true);

$balance1 = $json1a[key($json1a)]['final_balance'];

echo $balance1;
© www.soinside.com 2019 - 2024. All rights reserved.