php中实现字符串翻转的方法
字符串:$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>";
相关推荐
stulen 2020-08-15
fengzhiwu 2020-08-01
xiaobaif 2020-06-14
lemonzhangyan 2020-06-13
Crazyshark 2020-06-13
weikaixxxxxx 2020-06-13
有梦就能实现 2020-06-10
shengnanonly 2020-06-03
oraclemch 2020-05-30
poplpsure 2020-05-27
zuihaobushi 2020-04-30
luckymaoyy 2020-04-29
LinuxOracle 2019-07-26
liusarazhang 2020-06-28
fujuan000 2020-04-30
xiaoseyihe 2020-04-28
JackLang 2020-04-25