This article mainly introduced the implementation of PHP string flipping method, has a good reference value, following the small series to see it together
String: $str = "ABCDEFG";
Method one (directly using PHP's own function Strrev ($STR))
print_r(strrev($str));
Using for loop mode, Str_split ($STR)
$newArrOne = [];//Initializes a new array $newStrOne = ';//Initializes 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>";
Using for loop mode, strlen ($SUBSTR)
$newStrTwo = ";//Initializes 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>";
Using for loop mode, strlen ($SUBSTR)
$newStrThree = ";//Initializes a new string $arrcountthree = strlen ($STR); for ($i = $arrCountThree; $i >=0; $i-) {@ $newStrThree. =$ str[$i];} echo "<pre>";p rint_r ($newStrThree). " \ n "; echo" </pre> ";