php字符串如何按照单词进行反转?本文主要介绍了php字符串按照单词进行反转的方法,涉及php中array_reverse、explode及implode等函数的使用技巧,希望对大家来哦接字符串反转有所帮助。
具体分析如下:
下面的php代码可以将字符串按照单词进行反转输出,实际上市现将字符串按照空格分隔到数组,然后对数组进行反转输出
<?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;
?>输出结果如下:
word by string a Reversing
立即学习“PHP免费学习笔记(深入)”;
相关推荐:
以上就是php字符串中反转单词的方法的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号