下面的PHP代码可以将字符串按照单词进行反转输出,实际上市现将字符串按照空格分隔到数组,然后对数组进行反转输出
/**
* PHP字符串按照单词进行反转
*
* @param
* @arrange 512-笔记网: www.www.jb51.cc
**/
$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;
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
输出结果 word by string a Reversing 原文链接:https://www.f2er.com/php/528395.html