Re: Sort by string length...

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

 



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@xxxxxxxxxxxxx> 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
------------------------------------------------------->>

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