Can I merge an array, or remove duplicates from an array in PHP >=5.4 using a closure, in the same fashion as it can be done in Objective C using a block, or in C++ using a lambda ?
- Is it possible to use a predicate/closure/block/lambda as a parameter to such functions.
I.e:
$a = array('blah','bleh');
$b = array('blih, 'bloh');
$arr = array_merge( function() use (&$a,&$b) { return $a == $b ? true : false; } );
(Above example is oversimplified, I want to do this for Objects).
- Can it be done inline or should I always define the closure as an $var ?
- Is there a performance gain, or does it run the same ?
array_unique(array_merge())
? – deceze Mar 28 '13 at 16:32