【问题标题】:how loop through a JSON Array of bitcoin transaction data如何遍历比特币交易数据的 JSON 数组
【发布时间】:2017-01-14 07:53:48
【问题描述】:

我的代码是:

$requesturl='https://blockchain.info/tx-index/1fda663d2584425f192eae045d3809950883ebe50f2222f98ef7d31f414f3f96?format=json';
$ch=curl_init($requesturl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$cexecute=curl_exec($ch);
curl_close($ch);
$result = json_decode($cexecute,true);
// to get the first i use 
echo $result['out'][0]['addr'];
to get the second I use
echo $result['out'][0]['addr']; 

现在我的要求是使用 for each 但它的抛出错误来查看数组:

foreach ($result['out'] as $adressee) {
   echo $adressee.'<br>';
}

【问题讨论】:

  • 这个问题的标题到底是什么意思?
  • @duskwuff 问题只是用户想要遍历 json 响应。该json数据是否为比特币交易信息无关紧要。

标签: php json foreach blockchain


【解决方案1】:
 for($i=0; $i<count($result['out']); $i++) {

   echo $result['out'][$i]["addr"].'<br>';
  }

PHP 手册中的一些示例代码帮助我想出了这个解决方案

【讨论】:

    猜你喜欢
    • 2021-04-15
    • 1970-01-01
    • 2014-01-22
    • 1970-01-01
    • 1970-01-01
    • 2022-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多