Creating vertical button layout in Telegram bot inline keyboard

I’m working on a Telegram bot using PHP and I’m having trouble with the button arrangement in my inline keyboard. Right now all my buttons appear in a single horizontal row which makes the text get truncated.

$buttonLayout = [
    'inline_keyboard' => [['text' => $locationName, 'callback_data' => $locationId]],
];
$keyboardMarkup = json_encode($buttonLayout, true);
$messageData = [
    'chat_id' => $userId,
    'reply_markup' => $keyboardMarkup,
    'text' => 'Select a location from the list below to view its map.',
    'disable_notification' => true
];

The problem is that when I have multiple buttons, they all show up side by side horizontally and the button text gets cut off showing something like “Location Na…”. I want to display them vertically instead, with each button on its own row so the full text is visible. How do I modify the keyboard structure to achieve this vertical layout?

Your array structure’s the problem. Each button needs its own array to make separate rows. Right now you’ve got all buttons in one nested array, so they’re cramming into a single horizontal row. Fix it like this: $buttonLayout = [ ‘inline_keyboard’ => [ [[‘text’ => $locationName1, ‘callback_data’ => $locationId1]], [[‘text’ => $locationName2, ‘callback_data’ => $locationId2]], [[‘text’ => $locationName3, ‘callback_data’ => $locationId3]] ] ]; Each outer array = one row. Each inner array = the buttons for that row. Since you want them stacked vertically, put just one button per row. That way each button gets its own line and shows the full text without getting cut off.

To achieve vertical buttons in your Telegram bot’s inline keyboard, ensure each button is placed in its own array. Instead of having all buttons in one nested array, separate them out. Use the following structure for your button layout: 'inline_keyboard' => [[['text' => $locationName1, 'callback_data' => $locationId1]], [['text' => $locationName2, 'callback_data' => $locationId2]], [['text' => $locationName3, 'callback_data' => $locationId3]]]. This format allows each button to be displayed on a new line, ensuring complete text visibility.

yep, u gotta fix that nesting. each button needs its own array, like [['text' => 'btn1', 'callback_data' => 'id1']], [['text' => 'btn2', 'callback_data' => 'id2']]. this way, they stack and text won’t get cut off.