On Wed, 22 Oct 2003 11:21:13 -0700, you wrote:

>I've been scouring the php.net site for a few hours now trying to find a 
>viable way to sort a single dimensional array( array('0'=>'fddfsdsfdds', 
>'1'=>','ddddd','2' => 'gofofle'); )..... so that the longest lengthed 
>item is at the top, and the smallest lengthed item is at the bottom.... 
>is there a function to do this... example:

<?php

function cmp ($a, $b) {
    $a = strlen ($a);
    $b = strlen ($b);

    if ($a == $b) return (0);
    return (($a > $b) ? -1 : 1);
}

$a = array ('a', 'aa', 'aaa', 'aaaa', 'aaaaa');

usort ($a, "cmp");

print_r ($a);

?>

Standard warning: usort() has side-effects:

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

Reply via email to