Reverse string without strrev

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

    You can use this code to reverse a string without using the reserved function in php.

    Code:

    =0; $x--) {
           $y .= $y[$x];
           $y[$x] = NULL;
     }
    
    echo $y;
    
    }
    str_rev("I am a student");
    ?>
    

    Output:

    tneduts a ma I
    

    In the above code, we have passed the value of the string as the parameter.We have performed the string reversal using for loop.

提交回复
热议问题