Skip to content
Advertisement

How to check duplicate values in multidimensional associative array?

I have an associative multidimensional array with multiple state ids:

JavaScript

Now I want to find duplicate ids for us_states_ids as you can see index 1 has id of 15 same as index 2. How can I achieve this?

Advertisement

Answer

Try looping the array and play around with array_intersect on current “us_state_ids” with the previous one if it is not the first iteration.

JavaScript

then $duplicates will have the duplicates. The above code is untested, it’s just for a reference.

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