Home  >  Article  >  Backend Development  >  php中如何优雅的将一个字符串打乱顺序然后输入(不利用数组)?

php中如何优雅的将一个字符串打乱顺序然后输入(不利用数组)?

WBOY
WBOYOriginal
2016-06-06 20:27:471482browse

后台返回的字符串,需要将字符串中字符的顺序打乱然后输出,我想到了将字符串切割成数组,然后利用数组的shuffle()将数组打乱,最后将数组拼接成字符串再输出,但是这样感觉效率太低,如何优雅的实现这个需求?

回复内容:

后台返回的字符串,需要将字符串中字符的顺序打乱然后输出,我想到了将字符串切割成数组,然后利用数组的shuffle()将数组打乱,最后将数组拼接成字符串再输出,但是这样感觉效率太低,如何优雅的实现这个需求?

<code class="php">echo str_shuffle('http://segmentfault.com/q/1010000003776023');//q/20730hg/a70fptlnee6t3s0/11t/:otucm00.0m0</code>
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