Re: Array vs Hashes
| From: | Andrei Zmievski | Date: | Mon, 03 Dec 2001 21:25:49 +0000 |
| Subject: | Re: Array vs Hashes | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-72388@lists.php.net to get a copy of this message | ||
On Mon, 03 Dec 2001, Daniel Lorch wrote:
> Hi,
>
> I don't know whether this was already discussed before, but ..
>
> have you ever though about the fact that PHP is not very cleanly
> designed when looking at Arrays and Hashes? How can I predict whether
> a array/hash is sorted by it's INTEGER indices or it's STRING indices
> when using functions such as asort(), ksort() .. I don't know whether
> these indices are casted into the other type or not. Maybe, by
> accident I write $array['12'] = .. and from then PHP thinks I'm using
> string indices (thus casting all indices to string).
>
> Of couse, I could just try out but that isn't really a proper and
> clean language design. Shouldn't it be possible to FORCE either
> method? such as
>
> i_asort();
> str_asort();
>
> ok, that's a quite stupid proposal but you get the idea I hope :)
Eh, you can.
asort($array, SORT_NUMERIC);
asort($array, SORT_STRING);
-Andrei
As I was going up the stair, I met a man who wasn't there.
He wasn't there again today. I wish, I wish he'd stay away.
-Hughes Mearns