Re: reverse string without strrev();
| From: | Aschwin Wesselius | Date: | Thu, 28 Feb 2008 15:37:34 +0000 |
| Subject: | Re: reverse string without strrev(); | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-270573@lists.php.net to get a copy of this message | ||
Robert Cummings wrote:
There's always a tradeoff between speed and memory. Here's the low memory version: <?php $str = '1234567'; str_reverse_in_place( $str ); echo 'Reversed: '.$str."\n"; function str_reverse_in_place( &$str ) {Sorry, Rob, that function doesn't return anything..... ;-) -- Aschwin Wesselius <social> What you would like to be done to you, do that to the other.... </social>$a = 0; $z = strlen( $str ) - 1;while( $a < $z ) { $t = $str[$a]; $str[$a] = $str[$z]; $str[$z] = $t;++$a; --$z; }} ?>