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.
So this is the array data
Array (
[0] => Array ( [Key1] => value1 [Key2] => value2 [Key3] => value3 [Key4] => value4 ) [1] => Array ( [Key1] => value1 [Key2] => value2 [Key3] => value3 [Key4] => value4 ) [2] => Array ( [Key1] => value1 [Key2] => value2 [Key3] => value3 [Key4] => value4 ))
and I want it to be come out in this form in XML and Json
<xml>
<result>
<key1>value1</key1>
<key2>value2</key2>
<key3>value3</key3>
<key4>value4</key4>
</result>
<result>
<key1>value1</key1>
<key2>value2</key2>
<key3>value3</key3>
<key4>value4</key4>
</result>
<result>
<key1>value1</key1>
<key2>value2</key2>
<key3>value3</key3>
<key4>value4</key4>
</result>
</xml>
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.
Thanks