Skip to content

Dynamical array of callback's data for use in InlineKeyboard #533

Closed
@NabiKAZ

Description

@NabiKAZ

I know about InlineKeyboard class, can get each inline keyboard buttons as separated argument.

new InlineKeyboard($keyboard_buttons1, $keyboard_buttons2, ...);

Now I have $menus dynamical array of callback's data.
I want to read all the data with foreach and make category 3 each for every line I create.

Be like this:
image

Sample code:

$menus = [
	'x1'=>'y1',
	'x2'=>'y2',
	'x3'=>'y3',
	'x4'=>'y4',
	'x5'=>'y5',
	'x6'=>'y6',
	'x7'=>'y7',
];
$keyboard_buttons = [];
$keyboard_buttons_line = [];
$n = 0;
foreach ($menus as $key => $value) {
	$n++;
	$keyboard_buttons_line[] = [
		'text'          => $value,
		'callback_data' => $key,
	];
	if ($n % 3 == 0 || count($menus) == $n) {
		$keyboard_buttons[] = $keyboard_buttons_line;
		$keyboard_buttons_line = [];
	}
}

echo "<pre>";
print_r(new InlineKeyboard($keyboard_buttons[0], $keyboard_buttons[1], $keyboard_buttons[2])); //THIS HAVE BUG !!! (I don't know how many argument must be set.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions