RE: [PHP] Is there any function that sorts the contents of a string?

From: Date: Sat, 24 May 2003 14:10:05 +0000
Subject: RE: [PHP] Is there any function that sorts the contents of a string?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-148834@lists.php.net to get a copy of this message
> Hello, is there any function that will change "acb" to "abc", > "rys" to > "rsy" > and so on? Otherwise, how would I sort them? Convert your string into an array, sort the array, and then turn it back into a string. Or use some sort of sorting algorithm and go letter by letter. $l = strlen($string); for($x=0;$x<$l;$x++) { $ar[] = $string{$x}; } sort($ar); $sorted_string = implode('',$ar); Check that sort() is the right function you want to use, but something like that should work. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/

« previous php.general (#148834) next »