Re: PHP array unions
| From: | Adam Richardson | Date: | Fri, 14 Sep 2012 05:50:18 +0000 |
| Subject: | Re: PHP array unions | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-319078@lists.php.net to get a copy of this message | ||
On Wed, Sep 12, 2012 at 2:37 PM, Sebastian Krebs <krebs.seb@gmail.com> wrote:
> Hi,
>
> In PHP the array is in fact a hash map, but especially it is _used_ for
> nearly everything map-, set-, ...-like thing. So in short: The is no
> operator or built-in function, that merges two arrays _and_ treat them as
> set (instead of the hashmap, what they are). Your solution is the way to go.
Sure, I know about the underlying implementation. I was just hopeful
because several of the array functions handle the maps differently
depending on whether the keys are numeric or string or both.
If I wanted to get cute, I could store the value in the key (e.g.,
array('value 1' => 0, 'value 2' => 0, ...)), and that allows me to use
the '+' operator. In spite of the nice performance benefits of this
approach (leveraging the hashes benefits), the code that utilizes the
arrays becomes quite clunky.
Thanks,
Adam