【问题标题】:Getting single result from array [duplicate]从数组中获取单个结果[重复]
【发布时间】:2017-04-04 06:00:50
【问题描述】:
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 还是.. 帮助将不胜感激

【问题讨论】:

  • 它是一个对象,而不是一个数组。所以使用 $object->data->txid

标签: php arrays json object


【解决方案1】:

原始变量是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" 
    }
}

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-27
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多