Re: PHP array unions

From: Date: Fri, 14 Sep 2012 06:30:15 +0000
Subject: Re: PHP array unions
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-319079@lists.php.net to get a copy of this message
Op 14 sep. 2012 07:51 schreef "Adam Richardson" <simpleshot@gmail.com> het volgende: > > 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 > It doesn't need to be clunky.. just use array_flip and you've got the old array again.. -Matijn

« previous php.general (#319079) next »