Skip to content

Instantly share code, notes, and snippets.

@samuraee
Created May 17, 2019 14:23
Show Gist options
  • Save samuraee/96f95dfde868c52f3b05e3cb9e97c839 to your computer and use it in GitHub Desktop.
Save samuraee/96f95dfde868c52f3b05e3cb9e97c839 to your computer and use it in GitHub Desktop.
alireza task
<?php
$string = 'aboozar';
$dic = [
'a' => [1, 2, 'a'],
'b' => [3, 4, 'b'],
'o' => [5, 6],
'z' => [7, 8, 'd', 'f'],
'r' => [9, 0, 'e']
];
$chars = str_split($string);
$strLen = count($chars) - 1;
$tmp = [];
for ($i = 0; $i <= $strLen; $i++) {
$options = [];
$dicRow = $dic[$chars[$i]];
$dicRowLen = count($dicRow) - 1;
if ($i>0) {
for ($j = 0; $j <= $dicRowLen; $j++) {
foreach ($tmp as $t) {
$options[] = $t . $dicRow[$j];
}
}
} else {
for ($j = 0; $j <= $dicRowLen; $j++) {
$options[] = $dicRow[$j];
}
}
$tmp = $options;
}
print_r($options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment