Re: reverse string without strrev();
| From: | Nathan Rixham | Date: | Thu, 28 Feb 2008 12:39:02 +0000 |
| Subject: | Re: reverse string without strrev(); | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-270547@lists.php.net to get a copy of this message | ||
Aschwin Wesselius wrote:
Stut wrote:should it not use curlies? $tmp = ''; $str = 'abcdef'; for ($i = strlen($str)-1; $i >= 0; $i--) { $tmp.= $str{$i}; } echo $tmp; here's the "overkill" way to do it: $str = 'abcdef'; $rev = implode(array_flip(array_reverse(array_flip(str_split($str))))); echo $rev; *sniggers*Just because it works doesn't mean it's right. -StutWhat I meant was that I tested the script and it worked, so I didn't spot the flaw (wich is obvious and you were right). No big deal.