<?php //Using the PHP language, // have the function FirstReverse(str) // take the str parameter being passed and // return the string in reversed order. // For example: if the input string is // "Hello World and Coders" then your program should // return the string sredoC dna dlroW olleH //Input:"coderbyte" // //Output:"etybredoc" // // //Input:"I Love Code" // //Output:"edoC evoL I" function FirstReverse($str) { $newstr = ''; $length = strlen($str); for ($i = $length;$i >= 0; $i --) { $newstr .= $str[$i]; } return $newstr; } function FirstReverse2 ($str) { return strrev($str); } function method3 ($str) { $arr = str_split($str); //一个字符串分割成一个数组 $arr = array_reverse($arr); // 倒置数组 $str = implode('', $arr); // 分割数组,组成字符床 return $str; } echo method3('I Love Code'); echo FirstReverse('coderbyte');