RE: [PHP] Sort by string length...
| From: | Michael Sims | Date: | Tue, 21 Dec 2004 23:40:28 +0000 |
| Subject: | RE: [PHP] Sort by string length... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-204897@lists.php.net to get a copy of this message | ||
Russell P Jones wrote:
> Any idea how to sort an array by string length?
Use usort() in conjunction with a user defined function that compares the length of
both strings using strlen(). If brevity at the (possible) expense of clarity is
your thing, you can even use create_function() as your callback argument to usort()
to make this a one-liner. Of course if that were your sort of thing you'd probably
be using perl instead of PHP. :)
HTH