I have two arrays and I need two create a seperate array or alter the first one with data from 2nd array. using similar fields with different names for reference. I need to search through array 2 till I find the root_server_url
field that matches with array 1 root_server_uri
field. once there I want to take the name
field from array 2 and add it to the end of array1 or separate array with all those fields. I think I might be over (or under) thinking this. both arrays are fed from two different json api calls. all of the URIs are unique.
Array 1
(
[8] => Array
(
[latitude] => 34.3025556
[longitude] => -77.4598012
[weekday_tinyint] => 4
[start_time] => 19:00:00
[meeting_name] => On Time
[root_server_uri] => https://example.com/server/unique
)
[16] => Array
(
[latitude] => 37.5050744
[longitude] => -73.5075403
[weekday_tinyint] => 4
[start_time] => 19:00:00
[meeting_name] => Robot
[root_server_uri] => http://www.example.org/server/
)
)
Array 2
(
[35] => Array
(
[url] => https://example.org/rest/v1/
[root_server_url] => https://example.com/server/unique
[name] => Kentucky
[num_regions] => 2
[num_areas] => 13
[num_meetings] => 548
[server_info] => [{"version": "2.10.7", "versionInt": "2010007}]
[last_successful_import] => 2018-10-15T20:00:12.952796Z
)
[36] => Array
(
[url] => https://example.org/rest/v1/
[root_server_url] => http://www.example.org/server/
[name] => San Jose
[num_regions] => 0
[num_areas] => 2
[num_meetings] => 145
[server_info] => [{"version": "2.10.5", "versionInt": "2010005"}]
[last_successful_import] => 2018-10-15T19:55:23.045540Z
)
)
I would like my final array to look like this Final Array
(
[8] => Array
(
[latitude] => 34.3025556
[longitude] => -77.4598012
[weekday_tinyint] => 4
[start_time] => 19:00:00
[meeting_name] => On Time
[root_server_uri] => https://example.com/server/unique
[name] => Kentucky
)
[16] => Array
(
[latitude] => 37.5050744
[longitude] => -73.5075403
[weekday_tinyint] => 4
[start_time] => 19:00:00
[meeting_name] => Robot
[root_server_uri] => http://www.example.org/server/
[name] => San Jose
)
)
this is the code I have so far, any help would be greatly appreciated.
$root_server = "https://example.org/rest/v1/";
$meetings_respone = get($root_server . "/json/&data_field_key=latitude,longitude,weekday_tinyint,start_time,meeting_name");
$meetings = json_decode($meetings_respone, true);
$rootServers_respone = get($root_server . "/rest/v1/rootservers/");
$rootServers = json_decode($rootServers_respone, true);
foreach ($unique_meetings as $meeting) {
foreach ($rootServers as $rootServer) {
if (strtolower($rootServer['root_server_url']) == $meeting['root_server_uri']) {
$name = $rootServer['name'];
}
}
echo '{latitude: ' . $meeting['latitude']
. ', longitude: ' . $meeting['longitude']
. ', weekday_tinyint: \'' . $meeting['weekday_tinyint']
. ' \', start_time: \'' . $meeting['start_time']
. '\', meeting_name: \'' . $meeting['meeting_name']
. '\', root_server_uri: \'' . $meeting['root_server_uri']
. '\', name: \'' . $name . '\''
. '},' . "
";
}
function get($url) {
error_log($url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$errorno = curl_errno($ch);
curl_close($ch);
if ($errorno > 0) {
throw new Exception(curl_strerror($errorno));
}
return $data;
}