単語を数字の配列に変換する関数を書きました。フェ
$alphas = range('a', 'z');
function dig_to_string($string) {
global $alphas;
$array = str_split($string);
foreach($array as $a) {
$digits[] = array_search($a,$alphas);
}
return $digits;
}
$word = 'color';
$array = dig_to_string($word);
// Array ( [0] => 2 [1] => 14 [2] => 11 [3] => 14 [4] => 17 )
// Because 'c' is the second alphabet's letter, 'o' is 14th and so on.
// Means 'a' has 0-index
それを最適化する方法はありますか?