Reverse string without strrev

前端 未结 23 987
忘了有多久
忘了有多久 2020-12-13 13:19

Some time ago during a job interview I got the task to reverse a string in PHP without using strrev.

My first solution was something like this:

23条回答
  •  执念已碎
    2020-12-13 14:05

    you can try this..

    $string = "NASEEM";
    $total_word = strlen($string);      
    for($i=0; $i<=$total_word; $i++)
    {
       echo substr($string,$total_word-$i,1);
    }
    

提交回复
热议问题