Skip to content
Advertisement

PHP array unique by column

How to filter an array to give unique elements according to one or more columns. Example:

JavaScript

If we choose type and type2 as the unique column. The result of the algorithm should gives

JavaScript

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.

Advertisement

Answer

All you need is

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement