Reverse string without strrev

前端 未结 23 1012
忘了有多久
忘了有多久 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:18

    Its Too Simple

    //Reverse a String
    
    $string = 'Basant Kumar';
    $length = strlen($string);
    
    for($i=$length-1;$i >=0;$i--){
        echo $string[$i];
    }
    

提交回复
热议问题