Re: Array merge changes VALUE of keys, never mind the type
| From: | Steve Meyers | Date: | Fri, 28 Sep 2001 22:36:37 +0000 |
| Subject: | Re: Array merge changes VALUE of keys, never mind the type | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-66799@lists.php.net to get a copy of this message | ||
The "+" operator can be used with arrays, and it performs the same function
as array_merge. However, it does NOT reorder numeric keys -- it overwrites
them. So, you can use one or the other, depending on which type of
functionality you want.
See the user contributed notes at
http://www.php.net/manual/en/function.array-merge.php
The problem is really a fundamental flaw in PHP's arrays -- there is no
actual difference between associative and non-associative arrays. They are
both implemented as associative. A better approach would probably be to
have them be two different variable types, with different syntax.
It would be nice if there was an array_merge_associative that was exactly
like the "+" operator. I'd write it myself if I wasn't so busy with
schoolwork :)
"Nick Lindridge" <nick@macaw.demon.co.uk> wrote in message
news:20010928183522.B8089@macaw.demon.co.uk...
> Hi,
>
> Regarding what seems an array merge bug. This was
> quickly made bogus (:-), but I think that the
> point was missed. The issue isn't that the key
> was made numeric - I had it numeric and not a string
> in the first place. The issue is that the key value
> was changed.
>
> The array element key values had a meaning - otherwise
> I wouldn't have bothered by using keys at all.
>
> array_merge should not change the value of keys. It should
> just merge! If not a bug, it is a flaw.
>
> Nick
>