sendmany比特币命令问题中使用的动态PHP数组

时间:2013-11-15 09:26:55

标签: php arrays foreach bitcoin

我在比特币引擎的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.....); 

3 个答案:

答案 0 :(得分:9)

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

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

然后你可以用这种方式打电话给 sendmany

$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); 

答案 1 :(得分:1)

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

$chunks=array_chunk($to,100,true);
forach($chunks as $row) $bitcoin->sendmany($BuyerAccount,$row);

答案 2 :(得分:0)

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