How to filter an array to give unique elements according to one or more columns. Example:
array(
array('name'=>'toto', 'type'=>'1', 'type2'=> '2')
array('name'=>'tata', 'type'=>'1', 'type2'=> '3')
array('name'=>'titi', 'type'=>'1', 'type2'=> '2')
array('name'=>'tutu', 'type'=>'2', 'type2'=> '4')
array('name'=>'tete', 'type'=>'3', 'type2'=> '2')
)
If we choose type and type2 as the unique column. The result of the algorithm should gives
array(
array('name'=>'toto', 'type'=>'1', 'type2'=> '2')
array('name'=>'tata', 'type'=>'1', 'type2'=> '3')
array('name'=>'tutu', 'type'=>'2', 'type2'=> '4')
array('name'=>'tete', 'type'=>'3', 'type2'=> '2')
)
I can think of an algorithm by hashing the type concatenate with type2, store in a table and using isset to find the existence. But I'm not sure that's the best algorithm.
titiortototo discard?totoarray. Or if possible I want also a version that take the last found array. @Jakub: in my case, the data doesn't necessary come from a dump of SQLforeachand assignment, but is instead based on a map/filter/reduce implementation using PHP's array functions?