1

我在比特币引擎的 sendmany 交易中使用动态数组有以下问题,代码注释中描述的问题。

第 1 步创建数组
第 2 步将值插入数组
第 3 步打印一个数组以检查结果是否正确
第 4 步 sendmany(这是一个问题)见下文

<?php
//step 1 create array
$to = array();
//step 2 inserting values to array
while ( $row_users = mysqli_fetch_array($getting_allowed_users) )
{
          $to[] = array($row_users['user_bitcoin_wallet'] => $currency);
}

//step 3 print an array to check the result which is correct
print_r(array_values($to)); 

//step 4 sendmany (here is a problem)

// if I do it that way sendmany is only sending to first wallet which is indexed [0]
// I cannot to foreach as php  code structure is not allowing {} inside the command
$bitcoin->sendmany($BuyerAccount,$to[0]); 

//Question: How I can display all the values from my array in following place
$bitcoin->sendmany($BuyerAccount,ALL THE VALUES); 

//example
$bitcoin->sendmany($BuyerAccount,"walet1"=>0.1,"walet2"=>0.1,"walet2"=>0.1.....); 
4

3 回答 3

9

您以错误的方式构建$to数组。你需要一个键值对数组,你可以这样构建它:

$to[$row_users['user_bitcoin_wallet']] = $currency;

然后你可以这样调用sendman

$bitcoin->sendmany($BuyerAccount,$to);

你的代码变成了:

<?php
//step 1 create array
$to = array();

//step 2 inserting values to array
while ( $row_users = mysqli_fetch_array($getting_allowed_users) )
{
          $to[$row_users['user_bitcoin_wallet']] = $currency;
}

//step 3 print an array to check the result which is correct
print_r(array_values($to)); 

//step 4 sendmany

$bitcoin->sendmany($BuyerAccount,$to); 
于 2013-11-17T10:35:59.203 回答
1

您可能会考虑拆分该数组,因为一个请求中的太多可能对比特币守护进程来说有点多。

$chunks=array_chunk($to,100,true);
forach($chunks as $row) $bitcoin->sendmany($BuyerAccount,$row);
于 2013-11-18T21:28:16.580 回答
0

Paolo 给出了一个很好的答案,你可以->sendmany()在这里找到官方文档: 关于 Mike Gogulski 的 bitcoin-php 官方文档

于 2013-11-19T17:43:05.423 回答