如何在php中获取数组的特定区域对象?

时间:2017-06-15 19:09:30

标签: php

我正在使用比特币API生成比特币地址。比特币API的变量返回完整数组,我只得到" available_balance"部分。 这部分只是:

[available_balance] => 0.00138592

代码是:

$data=$block_io->get_address_balance(array('type' => 'received', 'addresses' => '3KHBGTRGFEgRHub8z5VUyT9L5ZUASpWZ'));

function pr($data)
{
    echo "<pre>";
    print_r($data); // or var_dump($data);
    echo "</pre>";
}

pr($data);

输出是:

stdClass Object
(
    [status] => success
    [data] => stdClass Object
        (
            [network] => BTC
            [available_balance] => 0.00138592
            [pending_received_balance] => 0.00000000
            [balances] => Array
                (
                    [0] => stdClass Object
                        (
                            [user_id] => 5
                            [label] => Lalaa
                            [address] => 3KHBGTRGFEgRHub8z5VUyT9L5ZUASpWZ
                            [available_balance] => 0.00138592
                            [pending_received_balance] => 0.00000000
                        )

                )

        )

)

2 个答案:

答案 0 :(得分:1)

$stdClass->data->balances[0]->available_balance

你是如何获得价值的

或者,如果你想要外层一级,你可以这样做:

$stdClass->data->available_balance

答案 1 :(得分:0)

试试这个:

$res_arr=array();
foreach($data->data->balances as $value) {
    $res_arr[] =$value->available_balance;
}