Skip to content
Advertisement

How to group subarrays by a column value?

I have the following array

JavaScript

How can I group the array by id? Is there any native php functions are available to do this?

While this approach works, I want to do this using a foreach, since with the above I will get duplicate items, which I’m trying to avoid?

On the above example id have 2 items, so its need to be inside of the id

Advertisement

Answer

There is no native one, just use a loop.

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