I have an array with this structure:
http://api.tvmaze.com/search/shows?q=girls
And I have this other array that the itunes api gives me:
https://itunes.apple.com/search?term=jack&limit=2
{
"resultCount": 1,
"results": [
{
"wrapperType": "track",
"kind": "feature-movie",
"trackId": 735814806,
"artistName": "Francis Ford Coppola",
"trackName": "Jack",
"trackCensoredName": "Jack",
"trackViewUrl": "https://itunes.apple.com/us/movie/jack/id735814806?uo=4"
}
]
}
What I need is to create an array with only one structure:
{
"resultados": [
{
"nombre": "track",
"longDescription": "feature-movie",
"imagen": url,
"busquedaobtenidade": "itunes"
},
{
"nombre": "track 2",
"longDescription": "feature-movie 2",
"imagen": url 2,
"busquedaobtenidade": "tv maze"
}
]
}
This is the code that I have so far, the only thing I do here is the data merge but it is not the result that I really want
<?php
$content=file_get_contents("https://itunes.apple.com/search?term=jack&limit=2");
$json = json_decode($content, true);
// print_R($json);
$count=count($json);
// for($i=0;$i<$count;$i++)
// {
// echo $json['results'][$i]['trackName'].'<br>';
// echo $json['results'][$i]['longDescription'].'<br>';
// }
?>
<?php
$contenttwo = file_get_contents("http://api.tvmaze.com/search/shows?q=girls");
$jsontwo = json_decode($contenttwo, true);
// print_r($jsontwo);
$resultado = array_merge($json, $jsontwo);
print_r($resultado);
// $pila = array();
// array_push($pila, $json, $jsontwo);
// print_r($pila);
?>
How could I do it or is there a library to do it?
You can independently bring the data from the two places and save the results in a single
array
, in this case I would not do onearray merge
since the data is very different from each other. The only thing to take into account is the format of the data obtained to go through them, for example withforeach
, and obtain the results that interest you in each case.Example:
Result