新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
php怎么反轉(zhuǎn)字符串a(chǎn)bcdefg
本教程操作環(huán)境:windows7系統(tǒng)、php7.1版、DELL G3電腦

成都創(chuàng)新互聯(lián)公司主營陜州網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,手機(jī)APP定制開發(fā),陜州h5小程序制作搭建,陜州網(wǎng)站營銷推廣歡迎陜州等地區(qū)企業(yè)咨詢
php反轉(zhuǎn)字符串“abcdefg”
方法1:使用字符串反轉(zhuǎn)函數(shù)strrev()
PHP 中提供了大量用來處理字符串的內(nèi)置函數(shù),例如想要進(jìn)行字符串反轉(zhuǎn),就可以使用strrev()函數(shù)。
strrev() 函數(shù)反轉(zhuǎn)字符串,返回已反轉(zhuǎn)的字符串。
示例:反轉(zhuǎn)字符串“abcdefg”
"; echo "字符串反轉(zhuǎn)后:".strrev($str); ?>
方法2:利用for語句、substr()拼接
-
使用for語句倒序遍歷字符串
-
使用substr()函數(shù)從后向前截取一個個字符,并拼接成新字符串
示例:反轉(zhuǎn)字符串“abcdefg”
";
var_dump($str);
$result = '';
$len = strlen($str);//獲取字符串長度
for ($i = $len-1; $i>=0; $i--){
$result.= substr($str,$i,1);
}
echo "字符串反轉(zhuǎn)后:
";
var_dump($result);
?>
網(wǎng)站標(biāo)題:php怎么反轉(zhuǎn)字符串a(chǎn)bcdefg
網(wǎng)站網(wǎng)址:http://fisionsoft.com.cn/article/dpgpipe.html


咨詢
建站咨詢
