我想爲我的編碼找到適當的解決方案。如何在php中升序oredr中安排給定字符串的單詞?
步驟1。我首先分解成陣列
步驟2。然後分裂每個爆炸值
步驟3。然後由for循環排序
<?php
$st ="It is a test";
$exp = explode(' ',strtolower($st));
print_r($exp);
$c =0;
$p =0;
for($i=0;$i<count($exp);$i++){
$t = str_split($exp[$i]);
$ch = $t[0];
if($c==0){
$arr[$p]=$exp[$i];
$temp = $ch;
}else{
if(ord($ch)<ord($temp)){
$tp = $arr[$p-1];
$arr[$p-1] = $exp[$i];
$arr[$p] = $tp;
}else{
$arr[$p] = $exp[$i];
}
}
$temp = $ch;
$p++;
$c++;
}
print_r($arr);
?>
任何幫助,將不勝感激。
按字母順序發佈預期產量 –
? – MuthaFury
是按字母順序排列的排列...... –