php字符串按照单词进行反转的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了php字符串按照单词进行反转的方法。分享给大家供大家参考。具体分析如下:

下面的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注入方法集锦第1/2页

'%23  ' and passWord='mypass  id=-1 union select 1,1,1&nbs...

PHP中call_user_func_array回调函数的用法示例

call_user_func_array call_user_func_array — 调用回调函数,并把一个数组参数作为回调函数的参数 mixed call_user_func_a...

php根据某字段对多维数组进行排序的方法

本文实例讲述了php根据某字段对多维数组进行排序的方法。分享给大家供大家参考。具体分析如下: 根据某字段对多维数组进行排序,在看到array_multisort方法的作用时突然想到,可以...

PHP实现邮件群发的源码

复制代码 代码如下: <?php  // 请求 PHPmailer类 文件  require_once("class.phpmailer.php");...

PHP高精确度运算BC函数库实例详解

本文实例讲述了PHP高精确度运算BC函数库。分享给大家供大家参考,具体如下: <?php /*************************************...