Created
May 17, 2019 14:23
-
-
Save samuraee/96f95dfde868c52f3b05e3cb9e97c839 to your computer and use it in GitHub Desktop.
alireza task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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