Home >Backend Development >PHP Tutorial >How to reverse php string by word_PHP tutorial

How to reverse php string by word_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:02:591167browse

How to reverse php string according to words

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

<?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;
?>

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/969345.htmlTechArticleHow to reverse php string according to words. 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 p...
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