I am trying to get some data off my DB and then trying to display it in XML and JSON. After I select everything from the db, I add everything to an array called $data. So depending on how I want it to be displayed, I can simply json_encode() it or use some lib ( This One ) to convert to XML. Now my problem/question is that I am trying to form the output style within the array so all I have to do in encode it and output it.

Now what I am trying to find a solution for a way to make those arrays with a key result so when I convert the array directly to json or xml, I dont have to make additional changes to make every result entry abide to the result tag.

Is there a way to do this? Adding every array to key result overrides all the entries and outputs only the last entry.

Hello, I know I can do that but the library supports nested arrays as well.. but, this doesnt help me because when I encode with json it just shows the entry but doesnt label the entries with the result tag, it just shows the entries.. –
–
KartikJul 22 '11 at 20:15

Assuming your outer array is called $array use the [] syntax. This will give you an array key called 'result' which itself is an indexed array. When converted to XML, I believe (though have not tested) that its output will be what you are looking for.