Skip to content
Advertisement

combine array values in sub array?

When I retrieve articles information from a mysql database I got an array like this:

JavaScript

And because the article is in more than one category, it retrieve the article information more than once. What I need to do is to combine the category names into a sub array if they have the same ArticleID so the result become like:

JavaScript

Advertisement

Answer

You can build a new array using ArticleID as the keys:

JavaScript

Output based on your question:

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