字符串:$str = "abcdefg";
直接运用php自带函数strrev($str)
print_r(strrev($str));
运用for轮回体式格局,str_split($str)
$newArrOne = [];//初始化一个新的数组 $newStrOne = '';//初始化一个新的字符串 $newArrOne = str_split($str); $arrCount = count($newArrOne); for ($i=0; $i < $arrCount; $i++) { $newStrOne.=$newArrOne[$i]; } echo "<pre>"; print_r($newStrOne); echo "</pre>";
运用for轮回体式格局,strlen($substr)
$newStrTwo = '';//初始化一个新的字符串 $arrCountTwo = strlen($str); for ($i=1; $i <= $arrCountTwo; $i++) { $newStrTwo.=substr($str, -$i, 1); } echo "<pre>"; print_r($newStrTwo)."\n"; echo "</pre>";
运用for轮回体式格局,strlen($substr)
$newStrThree = '';//初始化一个新的字符串 $arrCountThree = strlen($str); for ($i = $arrCountThree; $i>=0;$i--) { @$newStrThree.=$str[$i]; } echo "<pre>"; print_r($newStrThree)."\n"; echo "</pre>";
引荐教程:PHP视频教程
以上就是php怎样完成字符串翻转的细致内容,更多请关注ki4网别的相干文章!