首页 > 编程技术 > php

php字符串按照单词逐个进行反转的方法

发布时间:2015-3-15 10:40

本文实例讲述了php字符串按照单词进行反转的方法。
分享给大家供大家参考。
具体分析如下:

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

<?php
$s = "Reversing a string by word";
 
$words = explode(' ',$s);
 
$words = array_reverse($words);
 
$s = implode(' ',$words);
print $s;
?>

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


标签:[!--infotagslink--]

您可能感兴趣的文章: