Sorting an array by value length.
| From: | Rolf Brusletto | Date: | Wed, 22 Oct 2003 18:21:13 +0000 |
| Subject: | Sorting an array by value length. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-167124@lists.php.net to get a copy of this message | ||
Hey all -
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:
$arrayToSort = array('0' => 'shorter_length', '1' => 'longer_than_longer_than_shorter_length', '2' => 'longer_than_shorter_length');
and I would like to get... whether the keys change or not..
$arrayToSort[0] == 'longer_than_longer_than_shorter_length';
$arrayToSort[1] == 'longer_than_shorter_length';
$arrayToSort[2] == 'shorter_length';
any ideas?
Rolf Brusletto
www.phpExamples.net