How to Implement php string flip ?, Php string flip
String: $ str = "abcdefg ";
// Method 1 (directly use the built-in function strrev ($ str) in php ))
print_r(strrev($str));
// Use the for loop method, str_split ($ str)
$ NewArrOne = []; // initialize a new array $ newStrOne = ''; // initialize a new string $ newArrOne = str_split ($ str ); $ arrCount = count ($ newArrOne); for ($ I = 0; $ I <$ arrCount; $ I ++) {$ newStrOne. = $ newArrOne [$ I];} echo "<pre>"; print_r ($ newStrOne); echo "</pre> ";
// Use the for loop method, strlen ($ substr)
$ NewStrTwo = ''; // initialize a new string $ arrCountTwo = strlen ($ str); for ($ I = 1; $ I <= $ arrCountTwo; $ I ++) {$ newStrTwo. = substr ($ str,-$ I, 1);} echo "<pre>"; print_r ($ newStrTwo ). "\ n"; echo "</pre> ";
// Use the for loop method, strlen ($ substr)
$ NewStrThree = ''; // initialize a new string $ arrCountThree = strlen ($ str); for ($ I = $ arrCountThree; $ I >=0; $ I --) {@ $ newStrThree. = $ str [$ I];} echo "<pre>"; print_r ($ newStrThree ). "\ n"; echo "</pre> ";