【发布时间】:2017-11-09 11:12:00
【问题描述】:
在 for 循环中我想使用发送消息方法(电报机器人)。
几次 ($arrlength),只有一次与文本(不是几次,总是 1 次)。
例如,这个 for 循环可能重复 20 次,我想发送 20 次消息和 1 次文本,但我上面的代码发送了几次带有文本的消息!然后我想我应该从 for 循环中取出我的发送消息方法并将所有索引数组保存在另一个数组中。
例如:这个 for 循环重复 3 次,我想将所有 3 个索引保存在另一个数组中,然后在 for 循环中使用发送消息方法
//var :
$saves =array();
$saves_id =array();
$saveus = array();
$resultt = $conn->query("SELECT performer,file_id,title FROM databasebot
WHERE performer = '$message' or title = '$message'");
while ($row=mysqli_fetch_row($resultt))
{
// array title
$saves[] = $row[2];
//array file_id
$saves_id[] = $row[1];
}
$arrlength = count($saves);
for($x = 0; $x <= $arrlength; $x++) {
$poets['keyboard'][] = array($saves[$x]);
$jsonPoets= json_encode($poets);
//send message method ... !
// chat_id , text , reply_markup are required in sendmessage method
$url= "https://api.telegram.org/bot".$token."/sendMessage?
chat_id=".$chat_id."&text= choose song : "."&reply_markup=".$jsonPoets;
file_get_contents($url);
}
也许我可以这样做:
for($x = 0; $x <= $arrlength; $x++) {
$poets['keyboard'][] = array($saves[$x]);
// this in not working ... !
$saveus[$x][] = $poets[$x] +$saveus[$x];
}
$jsonPoets= json_encode($saveus);
$text= "song : ";
$url= "https://api.telegram.org/bot".$token."/sendMessage?
chat_id=".$chat_id."&text=".$text."&reply_markup=".$jsonPoets;
file_get_contents($url);
我能做什么?
【问题讨论】:
标签: php arrays for-loop telegram-bot