<?php
$keyboard_ru = [
1 => [], 2 => ['А','Б','В','Г',], 3 => ['Д','Е','Ж','З',],
4 => ['И','Й','К','Л',], 5 => ['М','Н','О','П',], 6 => ['Р','С','Т','У',],
7 => ['Ф','Х','Ц','Ч',], 8 => ['Ш','Щ','Ъ','Ы',], 9 => ['Ь','Э','Ю','Я',],
0 => [],
];
$keyboard_en = [
1 => [], 2 => ['A','B','C',], 3 => ['D','E','F',],
4 => ['G','H','I',], 5 => ['J','K','L',], 6 => ['M','N','O',],
7 => ['P','Q','R','S'], 8 => ['T','U','V',], 9 => ['W','X','Y','Z',],
0 => [],
];
$input_str = 757;
$variants_ru = get_variants($keyboard_ru, $input_str);
print_r($variants_ru);
$variants_en = get_variants($keyboard_en, $input_str);
print_r($variants_en);
function get_variants($keyboard, $input_str)
{
$input_codes = str_split($input_str, 1);
$groups = [];
foreach($input_codes as $idx => $code) {
foreach($keyboard as $num_code => $chars) {
if($num_code == $code && !empty($chars))
{
foreach($chars as $char) {
$groups[$idx][] = $char;
}
}
}
}
//get combinations
$result = array(array());
foreach ($groups as $property => $property_values) {
$tmp = array();
foreach ($result as $result_item) {
foreach ($property_values as $property_value) {
$tmp[] = array_merge($result_item, array($property => $property_value));
}
}
$result = $tmp;
}
return array_map('join', $result);
}