Re: Bug #765: new kusort() function (or similar)
| From: | Zeev Suraski | Date: | Tue, 22 Sep 1998 19:43:41 +0000 |
| Subject: | Re: Bug #765: new kusort() function (or similar) | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-1421@lists.php.net to get a copy of this message | ||
On Tue, 22 Sep 1998, Jean-Marc Libs wrote:
> Actually, it's the other way round. I am using fixed-length strings
> as keys, some of which get interpreted as integers by PHP. Then I wish
> to do an alphabetic sort on the keys, and ksort separates some keys
> (those beginning by 1, which look like numbers) from the others.
>
> > Because of this, implementing a builtin function that
> > will behave just like ksort() except it'll convert string indices to
> > numbers seems redundant to me.
>
> I thought it would be the other way round: treat everything as strings
> for sorting purposes.
Either way, it doesn't really matter.
> > You don't have to redesign your script at all. You can easily implement
> > any sort order you want using the usort():
> >
> > function numeric_compare($i1,$i2)
> > {
> > return (int) $i1 - (int) $i2;
> > }
> >
> > usort($array, "numeric_compare");
> >
> > usort() was added in version 3.0.3, so you may need to upgrade before you
> > can use it. If you do, wait up for 3.0.4, it should be out today.
>
> I know about usort() and I considered it. But it sorts on values and I sort
> on keys. It still does not seem redundant to me. That's why I filed this
> request for kusort which does for ksort what usort does for sort.
> I already use 3.0.3 and I'd happilly install 3.0.4 and test it out
> when it's out, but it won't help.
It will. 3.0.4 adds uksort(), which is a key sort with a user defined
function. You should do OK with it.
Zeev
--
-----------------------------------------------------
Zeev Suraski <zeev@php.net>
For a PGP public key, finger bourbon@netvision.net.il
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net