首頁  >  文章  >  後端開發  >  php字符串按照单词进行反转的方法_PHP

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

WBOY
WBOY原創
2016-06-01 11:06:29772瀏覽

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

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

<&#63;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;
&#63;>

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

希望本文所述对大家的php程序设计有所帮助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn