Reverse a string with php

后端 未结 16 1116
南笙
南笙 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:12

    As others said, there's strrev() to do this.

    If you want to build it on your own (for learning?): your problem is that you're starting with your index one too high - a string of length 25 is indexed from 0 to 24, so your loop has to look like this:

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

提交回复
热议问题