Re: PHP array unions

From: Date: Wed, 12 Sep 2012 18:37:28 +0000
Subject: Re: PHP array unions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-319050@lists.php.net to get a copy of this message
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. Regards, Sebastian Am 12.09.2012 17:10, schrieb Adam Richardson:
Hi! So, PHP has the '+' array operator, which forms the union of arrays, but it does so by key. What I'm looking for is a function that forms the union of arrays based on value. Currently, I use code like the following: array_unique(array_merge($array1, $array2, $array3)); This is useful to me because I tend to program using functional programming principles. Just want to make sure I'm not missing a core function that already does this. If there's not a core function, I might just build an array_union extension because the functionality is so common in my codebases. Thanks, Adam


« previous php.general (#319050) next »