$buttons = ['пример1', 'пример2', 'пример3'];
$rows = '2_1';
$rowsSegments = explode('_', $rows);
$keyboard = [
'keyboard' => []
];
for($i = 0; $i < count($rowsSegments); $i++) {
for($n = 0; $n < $rowsSegments[$i]; $n++) {
$keyboard['keyboard'][$i]['text'] = $buttons[$i];
}
}