Reverse a string with php

后端 未结 16 1083
南笙
南笙 2020-12-03 23:42

I am trying to find a way to reverse a string, I\'ve seen alternatives but i wanted to to it this way thinking outside the box and not using anyone else\'s code as an altern

16条回答
  •  攒了一身酷
    2020-12-04 00:21

    We can do String Reverse with help of following menthods

        $string = "Hello world!";
    
    1. 1st way to do:

      echo strrev($string);
      
    2. 2nd way to do:

       $stringSplit = str_split($string);
                  for ($i = $len-1; $i >=0;$i--)
                  {
                  echo $stringSplit[$i];
                  }
      

提交回复
热议问题