Skip to content
Advertisement

make output from array with same keys from the database

I get the information from the database. For example, my database data is as follows: I get the information from the database. For example, my database data is as follows:

JavaScript

So in the php code section I use this method to get descriptions:

JavaScript

this is the output of this code:

JavaScript

But, my expected output is, like this:

JavaScript

I hope that with your guidance this problem will be solved for me, Thank You…

Advertisement

Answer

What this code does is index your output by the p_id value, then if there is not already some data there, it just adds a new element with the p_id . It then adds in the data with the description_name and description_value elements…

In the json_encode() it uses array_values() to remove the index used to build the data…

JavaScript

with some test data, this gives (plus formatting)…

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