字符串翻转

<?php
//字符串翻转
 function myrev($str)
{
    $arr = explode(' ', $str);
    $num = count($arr);
    for ($i = 0; $i < $num / 2; ++$i) {
        $temp = $arr[$i];
        $arr[$i] = $arr[$num - $i - 1];
        $arr[$num - $i - 1] = $temp;
    }

    return implode(' ', $arr);
}
    $str = 'This is PHP';
    echo myrev($str);    //PHP is This
    echo strrev($str);   //PHP si sihT

 

posted @ 2019-11-07 15:59  za_szybko  阅读(121)  评论(0编辑  收藏  举报