本文实例讲述了php字符串按照单词进行反转的方法。分享给大家供大家参考。具体分析如下:
下面的php代码可以将字符串按照单词进行反转输出,实际上市现将字符串按照空格分隔到数组,然后对数组进行反转输出
复制代码
1
2
3
4
5
6
7
8
9
10<?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; ?>
输出结果如下:
word by string a Reversing
希望本文所述对大家的php程序设计有所帮助。
最后
以上就是自然糖豆最近收集整理的关于php字符串按照单词进行反转的方法的全部内容,更多相关php字符串按照单词进行反转内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复