Re: Bug #765: new kusort() function (or similar)
| From: | Jean-Marc Libs | Date: | Tue, 22 Sep 1998 16:21:28 +0000 |
| Subject: | Re: Bug #765: new kusort() function (or similar) | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-1405@lists.php.net to get a copy of this message | ||
Hi Zeev, hi all,
Zeev Suraski wrote:
>
> On 22 Sep 1998 libs@cybercable.tm.fr wrote:
>
> > From: libs@cybercable.tm.fr
> > Operating system: Linux (irrelevant)
> > PHP version: 3.0.3
> > PHP Bug Type: Feature/Change Request
> > Bug description: new kusort() function (or similar)
> >
> > I'd be delighted if a new function similar to ksort
> > would appear in PHP3.
> >
> > 1/The requested functionality would be the following one:
> > 1.1/Consider an array:
> > $toto["001"]="a";
> > $toto["010"]="c";
> > $toto["100"]="d";
> > $toto["002"]="b";
> > $toto["110"]="e";
> >
> > 1.2/Sorting this array on its key with the requested
> > function would give:
> > key : value
> > 001 : a
> > 002 : b
> > 010 : c
> > 100 : d
> > 110 : e
> >
> > 1.3/Due to variable typing, ksort behaves differently
> > and sorts this way:
> > key : value
> > 010 : c
> > 100 : d
> > 110 : e
> > 001 : a
> > 002 : b
> >
> > 1.4/There is no practical way of getting the requested
> > functionality with the existing functions.
>
> But there is, exactly this:
>
> > Prepending zero or appending a dot work, of course,
> > but it lacks elegance, especially when you have to strip
> > the zero or the dot afterwards for use in the rest of
> > the script.
>
> I'm not sure that adding specific functions for this fairly rare situation
> is more elegant...
My point is, I don't believe it is fairly rare. I may be biased because
of what
I intend to do. I explain what I do below so you can decide if it is a
legit
use of PHP or if I should totally redesign the script.
It will have to be redesigned later with database use anyway when I have
free
time (yeah right).
What I do is, I scan a directory for files which contain data about
bugs. The
name files are split to extract info about package, set and test. I put
all data
I need in an array where set and test are keys to values which come
from inside the files.
So my key is at the same time a test number and also a string, which I
get from
the filename and which I use later to construct other filenames.
Then I can nicely separate collection of data and display of data.
To display, I just ksort() on all levels of my multi-dimensional array
and loop on the keys to format the data, reconstruct filenames to put in
URL links, etc...
The only glitch is, ksort does not really sort the keys in order. Yet I
feel
this is a fairly standard use of associative arrays. If the keys I use
do not
have any meaning to me (that is, if I have to append stuff to change the
behaviour of ksort), I might as well use fully numerical keys and
reformat
them into the proper strings later on.
It might even speed up the script. But it just defeats the purpose of
associative arrays as I understand them.
This is what I call inelegant: changing the data to suit the data
manipulation functions and then changing it back.
I hope I cleared up the issue,
I just looked a bit in the code. From the comments in
array_data_compare, I
gather that kusort() is more likely than a variant of ksort() doing what
I'd
like.
Jean-Marc Libs
--
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