为了账号安全,请及时绑定邮箱和手机立即绑定

有没有办法简化这个 foreach 循环?

有没有办法简化这个 foreach 循环?

PHP
HUH函数 2021-11-13 10:34:59
我想知道是否有任何方法可以简化这一点。它基本上将 JSON API 解码为数组,然后将每个value对象从对象添加到$utxos数组。如果可能,这就是我实际拥有并希望简化的内容:$utxos = array();$unspent = json_decode(file_get_contents("https://blockchain.info/unspent?active=1LaiteuxHEH4GsMC9aVmnwgUEZyrG6BiTH"), true)["unspent_outputs"];foreach ($unspent as $utxo) array_push($utxos, $utxo["value"]);
查看完整描述

1 回答

?
心有法竹

TA贡献1866条经验 获得超5个赞

这就是我想出的:

$unspent = json_decode(file_get_contents("https://blockchain.info/unspent?active=1LaiteuxHEH4GsMC9aVmnwgUEZyrG6BiTH"), true)["unspent_outputs"];
$utxos = array_column($unspent, "value")

感谢B. Fleming


查看完整回答
反对 回复 2021-11-13
  • 1 回答
  • 0 关注
  • 148 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号