Skip to content
Advertisement

Group array values based on key in php?

I have a array like this:

JavaScript

I want to group elements in the array based upon ‘No’ as primary key. The output should look like this:

JavaScript

Note that the Author’s value got merged with respect to the primary key ‘No’.Can anyone help me out from this, please?

I tried doing this:

JavaScript

Advertisement

Answer

You could use a generic function:

JavaScript

I added some sample code to test

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