0

Basically, I'm working with 2 API's in which I want to integrate inside one file, one of the API returns a JSON Array. The other returns an XML.

Here's the idea in which I want to be able to do

$arr = (array)file_get_contents(JSON API);
$arr2 = (array)simplexml_load_file("XML API");

$details['Details']['1'] = $arr['Details']['0'];
$details['Details']['2'] = $arr2['Details']['0'];

foreach($details['Details'] as $detail) {
 //do what i want with the array
}

But how can I get the JSON API inside this Array ? I'm sorry if it's hard to understand what I'm asking but it's the best I can explain.

there is a way to convert the JSON to an XML Document ?

Luc M
  • 16,630
  • 26
  • 74
  • 89
Curtis Crewe
  • 23
  • 1
  • 5
  • Please explain a bit more of why you want to do this. Are both API's returning the exact same object, but with different representation (one being JSON and the other XML)? Why are you wanting to combine them? – Jonathan M Mar 02 '13 at 20:03

2 Answers2

0

You can use array_merge()

 $details = array_merge($arr, $arr2);
John Conde
  • 217,595
  • 99
  • 455
  • 496
0

There is a way for converting the JSON to an XML Document at the Link. It would be helpful to you to manipulate the data as required by you

Community
  • 1
  • 1
Ajo Koshy
  • 1,205
  • 2
  • 21
  • 33