我如何在数组(php)数组中使用循环?

时间:2017-11-08 17:37:18

标签: php mysql arrays for-loop telegram-bot

我想在php的数组数组中使用Repeat循环(for,while和etc ...):

      for($x = 0; $x < $arrlength; $x++) {

         $poets = array(
        'keyboard' => array(

            array($saves[$x]) // this is just one array i don't want this !

        ),
    );
$url= "https://api.telegram.org/bot".$token."/sendMessage?
chat_id=".$chat_id."&text=".$text."&reply_markup=".$jsonPoets;
file_get_contents($url);


}

这不起作用,我想这样做:

 for($x = 0; $x < $arrlength; $x++) {

         $poets = array(
        'keyboard' => array(

       //i wanna do like this ...

            array($saves[$x])
          //array($saves[$x])
          //array($saves[$x])
                 .
                 .
                 .

        )
    );
$url= "https://api.telegram.org/bot".$token."/sendMessage?
chat_id=".$chat_id."&text=".$text."&reply_markup=".$jsonPoets;
file_get_contents($url);


}

这意味着我想在循环重复的数组中制作多个数组。

1 个答案:

答案 0 :(得分:1)

$poets= array('keyboard' => array());
for($x = 0; $x < $arrlength; $x++) {
   $poets['keyboard'][] = array($saves[$x]);
}

喜欢这个吗?