abstract:本文實例講述了php字符串按照單詞進行反轉(zhuǎn)的方法。分享給大家供大家參考。具體分析如下:下面的php代碼可以將字符串按照單詞進行反轉(zhuǎn)輸出,實際上市現(xiàn)將字符串按照空格分隔到數(shù)組,然后對數(shù)組進行反轉(zhuǎn)輸出<?php $s = "Reversing a string by word"; // break 
本文實例講述了php字符串按照單詞進行反轉(zhuǎn)的方法。分享給大家供大家參考。具體分析如下:
下面的php代碼可以將字符串按照單詞進行反轉(zhuǎn)輸出,實際上市現(xiàn)將字符串按照空格分隔到數(shù)組,然后對數(shù)組進行反轉(zhuǎn)輸出
<?php $s = "Reversing a string by word"; // break the string up into words $words = explode(' ',$s); // reverse the array of words $words = array_reverse($words); // rebuild the string $s = implode(' ',$words); print $s; ?>
輸出結(jié)果如下:
word by string a Reversing
更多關(guān)于php字符串按照單詞進行反轉(zhuǎn)的方法請關(guān)注PHP中文網(wǎng)(www.miracleart.cn)其他文章!