Skip to content
Advertisement

How to keep only unique objects in JSON array | PHP

I have the following JSON array, I would like to adjust the array to only keep unique name values, meaning id could be across numerous objects, but name must be unique, overall Tim and Jacob can only be listed once.

JavaScript

The following is what I have currently tried, but it looks at both values in the object, so it leaves them as is.

Result I am looking for:

JavaScript

Advertisement

Answer

You can write a function which goes through each of the entries in the array and removes them if their name has been seen before.

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