首页  >  文章  >  后端开发  >  php字符串中反转单词的方法

php字符串中反转单词的方法

*文
*文原创
2017-12-26 09:51:221239浏览

php字符串如何按照单词进行反转?本文主要介绍了php字符串按照单词进行反转的方法,涉及php中array_reverse、explode及implode等函数的使用技巧,希望对大家来哦接字符串反转有所帮助。

具体分析如下:

下面的php代码可以将字符串按照单词进行反转输出,实际上市现将字符串按照空格分隔到数组,然后对数组进行反转输出

<?php
$s = "Reversing a string by word";
// break the string up into words
$words = explode(&#39; &#39;,$s);
// reverse the array of words
$words = array_reverse($words);
// rebuild the string
$s = implode(&#39; &#39;,$words);
print $s;
?>

输出结果如下:
word by string a Reversing

相关推荐:

关于php 字符串函数的详细介绍

php 字符串函数教程与实例代码

php 字符串分割和比较介绍

以上是php字符串中反转单词的方法的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn