Home >Backend Development >PHP Tutorial >How to reverse php string according to words, php string word reversal_PHP tutorial

How to reverse php string according to words, php string word reversal_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:03:50837browse

How to reverse php string according to words, php string word reversal

The example in this article describes the method of reversing php string according to words. Share it with everyone for your reference. The specific analysis is as follows:

The following php code can reverse and output the string according to words. In fact, the string is separated into arrays according to spaces, and then the array is reversed and output

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

The output results are as follows:
word by string a Reversing

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/967733.htmlTechArticleHow to reverse php string according to words, php string word reversal This article tells the example of php string How to reverse words. Share it with everyone for your reference. Specific points...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn