如何在PHP中显示数组的特定元素

时间:2013-12-12 00:41:19

标签: php arrays bitcoin

我正在使用MtGOX API v2 example PHP code来查找比特币的当前价格。我的代码摘录看起来像这样:

<?php
$result = $mtGoxClient->getTicker();
?>

<pre>
    <?php print_r($result);?>
</pre>

我得到以下输出:

Array
(
    [result] => success
    [data] => Array
        (
            [high] => Array
                (
                    [value] => 1056.90000
                    [value_int] => 105690000
                    [display] => $1,056.90000
                    [display_short] => $1,056.90
                    [currency] => USD
                )

            [low] => Array
                (
                    [value] => 856.12300
                    [value_int] => 85612300
                    [display] => $856.12300
                    [display_short] => $856.12
                    [currency] => USD
                )

            [avg] => Array
                (
                    [value] => 947.15239
                    [value_int] => 94715239
                    [display] => $947.15239
                    [display_short] => $947.15
                    [currency] => USD
                )

            [vwap] => Array
                (
                    [value] => 943.98795
                    [value_int] => 94398795
                    [display] => $943.98795
                    [display_short] => $943.99
                    [currency] => USD
                )

            [vol] => Array
                (
                    [value] => 23521.92105774
                    [value_int] => 2352192105774
                    [display] => 23,521.92105774Â BTC
                    [display_short] => 23,521.92Â BTC
                    [currency] => BTC
                )

            [last_local] => Array
                (
                    [value] => 922.50002
                    [value_int] => 92250002
                    [display] => $922.50002
                    [display_short] => $922.50
                    [currency] => USD
                )

            [last_orig] => Array
                (
                    [value] => 922.50002
                    [value_int] => 92250002
                    [display] => $922.50002
                    [display_short] => $922.50
                    [currency] => USD
                )

            [last_all] => Array
                (
                    [value] => 922.50002
                    [value_int] => 92250002
                    [display] => $922.50002
                    [display_short] => $922.50
                    [currency] => USD
                )

            [last] => Array
                (
                    [value] => 922.50002
                    [value_int] => 92250002
                    [display] => $922.50002
                    [display_short] => $922.50
                    [currency] => USD
                )

            [buy] => Array
                (
                    [value] => 922.00000
                    [value_int] => 92200000
                    [display] => $922.00000
                    [display_short] => $922.00
                    [currency] => USD
                )

            [sell] => Array
                (
                    [value] => 922.50002
                    [value_int] => 92250002
                    [display] => $922.50002
                    [display_short] => $922.50
                    [currency] => USD
                )

            [item] => BTC
            [now] => 1386808426752872
        )

)

我将使用哪些PHP代码来获取[data] [high] [display_short](读取$ 1,056.90的那个)?

1 个答案:

答案 0 :(得分:1)

您将使用以下内容:

$price = $result['data']['high']['display_short'];

我强烈建议您阅读PHP.net documentation on arrays