我想向我的客户建议可能的单词,如下所示:
T.estte.sttes.tte.sttes.tT.E.S.T
现在我的代码将是 ?
<?php
$string = "test";
$array = str_split($string);
foreach($array as $letter){
echo $letter.".";
}
我希望这可以解决您的问题:
$string = "test";
$array = str_split($string);
$len = strlen($string);
$rand_indx = mt_rand(0,$len);
if ($rand_indx == $len) {
$array[$rand_indx] = ".";
} else {
for ($x=$len; $x > $rand_indx; $x--) {
$array[$x] = $array[$x-1];
}
$array[$rand_indx] = ".";
}
foreach($array as $letter){
echo $letter;
}