Re: Sort by string length...

From: Date: Wed, 22 Dec 2004 00:28:01 +0000
Subject: Re: Sort by string length...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-204912@lists.php.net to get a copy of this message
How about iterating though the strings and putting string values and lengths in an array: [begin untested code] $strings = array('i','am','who'); $string_count = array(); foreach ($strings as $string) { $string_count['value'][] = $string; $string_count['length'][] = strlen($string); } array_multisort($string_count['length'],SORT_ASC,SORT_NUMERIC,$string_count['value']); [/end untested code] This'll take an array of strings and sort them from shortest to longest. There may be some other function already made, this was just off the top of my head. On Tue, 21 Dec 2004 16:18:52 -0500 (EST), Russell P Jones <rjones@email.unc.edu> wrote: > Any idea how to sort an array by string length? > > Russ Jones > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- <<-------------------------------------------------------- Jasper Howard - Database Administration ApexEleven.com 530 559 0107 ------------------------------------------------------->>

« previous php.general (#204912) next »