Character flip is a piece of cake for php processing. php's string function strrev can be used for processing, for example, echostrrev (& quot; HelloWorld! & Quot;); // The output result is & quot ;! DlroWolleH & quot;
Character flip is a piece of cake for php processing. the strrev character string function of php can be processed as follows:
Echo strrev ("Hello World! "); // The output result is "! DlroW olleH"
However, sometimes during interviews, we often need to write a function to achieve the same effect as strrev. In fact, this is not difficult, for example:
/*** Function for string flip * @ param string $ str the string to be processed * @ return string the string that has been successfully flipped */function reverse ($ str) {if ($ str = '') {return null;} if (strlen ($ str) = 1) {return $ str;} else {$ string = ""; for ($ I = 1; $ I <= strlen ($ str); $ I ++) {$ string. = substr ($ str,-$ I, 1) ;}return $ string ;}} echo reverse ("Hello World! "); // The output result is "! DlroW olleH"