PHP string flip instance code. Character flip is a piece of cake for php processing. php's string function strrev can be used for processing, for example, echostrrev (HelloWorld !); The output result is! DlroWolleH is a piece of cake for php processing, but sometimes the interview character is flipped. the strrev 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:
/**
* String flip function
* @ Param string $ str the string to be processed
* @ Return string that is 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"
From: Shine's holy heaven
Repeated echo strrev (Hello World !); // The output result is! DlroW olleH but sometimes interviews...