从数组中获取单个结果

时间:2017-04-04 06:00:51

标签: php arrays json object

object(stdClass)#19 (2) { 
    ["status"] =>
        string(7) "success" 
    ["data"] =>
        object(stdClass)#14 (6) {
                ["network"] => 
                    string(3) "BTC" 
                ["txid"] =>
                    string(64) "128830010b4773bb9a88f9c53b67217f37caa092bfd477a81a2f41d6ea804e53"
                ["amount_withdrawn"] =>
                    string(10) "0.00087298"
                ["amount_sent"] =>
                    string(10) "0.00050000"
                ["network_fee"] =>
                    string(10) "0.00037298"
                ["blockio_fee"] =>
                    string(10) "0.00000000"
        }
}

我有这个数组,但我很难找到如何从中获取数据,如txid,我不确定是否会赞赏它的json或..帮助

1 个答案:

答案 0 :(得分:0)

原始变量是stdClass。您发布的输出看起来像var_dump

更好地格式化代码,可以显示如何从原始变量中获取数据

object(stdClass)#19 (2) { 
    ["status"]=> string(7) "success" 
    ["data"]=> object(stdClass)#14 (6) { 
        ["network"]=> string(3) "BTC" 
        ["txid"]=> string(64) "128830010b4773bb9a88f9c53b67217f37caa092bfd477a81a2f41d6ea804e53" 
        ["amount_withdrawn"]=> string(10) "0.00087298" ["amount_sent"]=> string(10) "0.00050000" 
        ["network_fee"]=> string(10) "0.00037298" 
        ["blockio_fee"]=> string(10) "0.00000000" 
    }
}

因此,您可以从txid获取$variable->data->txid,但只能从原始变量获取 。与var_export不同,var_dump不会输出有效的PHP代码,因此您无法从中获取它。