将项目添加到多级数组(Telegram Bot)

Add item to multi-level array (Telegram Bot)

我有以下数组:

$keyboard = ['inline_keyboard' => [[['text' => 'text1', 'callback_data' => 'something1']],[['text' => 'text2', 'callback_data' => 'something2']],]];

如何将一个元素(使用 textcallback_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']],]];

array_push 救援!

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

产量:

array(1) {
  ["inline_keyboard"]=>
  array(3) {
    [0]=>
    array(1) {
      [0]=>
      array(2) {
        ["text"]=>
        string(5) "text1"
        ["callback_data"]=>
        string(10) "something1"
      }
    }
    [1]=>
    array(1) {
      [0]=>
      array(2) {
        ["text"]=>
        string(5) "text2"
        ["callback_data"]=>
        string(10) "something2"
      }
    }
    [2]=>
    array(2) {
      ["text"]=>
      string(5) "text3"
      ["callback_data"]=>
      string(10) "something3"
    }
  }
}

http://sandbox.onlinephpfunctions.com/code/c92ad23fccc0c6d102761840f051cdb4b6c4084b