Get the App
SLTechnology News&Howtos  ›  Development  › 

How php reverses strings by word

Shulou Source: shulou.com Published: 2022-06-02 16:39:55 09月20日 Update

This article mainly introduces how php reverses the string by words, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.

Inversion method: 1, use the "explode (', $str)" statement to convert the string into an array; 2, use the "array_reverse ($arr)" statement to reverse the array and return the array in the opposite order of elements; 3, use the "implode (', $arr)" statement to convert the inverted array into a string.

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

Php reverses the string by word

Implementation method: followed by an array

First convert the string into array elements according to words

Then use array_reverse () to reverse the array

Then convert the inverted array to a string

Implementation code:

Output result:

Description:

The explode () function splits a string based on a string delimiter, that is, it splits a string into several substrings based on the delimiter, and then combines these substrings into an array and returns.

The array_reverse () function returns the array in the reverse order of elements.

The implode () function can convert an one-dimensional array to a string.

Thank you for reading this article carefully. I hope the article "how to reverse the string by word" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Characters strings arrays words articles elements functions statements delimiters methods order number number code value interest and at the same time tutorials more friends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB macOS vpn Huawei MySQL