我有以下数组:
$keyboard = ['inline_keyboard' => [[['text' => 'text1', 'callback_data' => 'something1']],[['text' => 'text2', 'callback_data' => 'something2']],]];
如何将一个元素(text
和callback_data
)添加到数组的末尾(在foreach循环中)?
所以我的目标是在一段时间后得到以下数组:
$keyboard = ['inline_keyboard' => [[['text' => 'text1', 'callback_data' => 'something1']],[['text' => 'text2', 'callback_data' => 'something2']],[['text' => 'text3', 'callback_data' => 'something3']],[['text' => 'text4', 'callback_data' => 'something4']],]];
答案 0 :(得分:1)
array_push救援!
jsonArray
<强>收率:强>
<?php
$keyboard = ['inline_keyboard' => [
[
['text' => 'text1', 'callback_data' => 'something1']
],
[
['text' => 'text2', 'callback_data' => 'something2']
],
]];
array_push($keyboard['inline_keyboard'], ['text' => 'text3', 'callback_data' => 'something3']);
var_dump($keyboard);
http://sandbox.onlinephpfunctions.com/code/c92ad23fccc0c6d102761840f051cdb4b6c4084b