Re: reverse string without strrev();

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Aschwin Wesselius wrote:
Stut wrote:
Just because it works doesn't mean it's right.

-Stut



What 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.


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*

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux