У меня есть массив, содержащий текущую информацию билета следующим образом:PHP: Перебрать два массива, найти матч, объединить
[0] => Array
(
[id] => 1155643
[text] => Physical Move and Assistance
[location] => 25158 16th Ave NE, Lynnwood, WA, 98110, USA
[company] => Blank Architecture, LLC.
[site] => Main
[contact] => First Last
[start_date] => 2016-07-30 18:00:00
[end_date] => 2016-07-30 22:00:00
[technician] => First Last
[hours] => 4
[status] => Firm
[ownerFlag] => 1
[lat] => 47.54601 //Incorrect latitude
[lng] => -122.22651 //Incorrect longitude
)
[1] => Array //There are 70+ more...
У меня есть еще один массив, из которого координаты расположения компании в настоящее время извлекается из:
[0] => Array
(
[company] => Rhodes and Associates
[lat] => 47.32026
[lng] => -122.30402
)
[1] => Array //There are 130+ more...
После извлечения данных о билетах (cURL) из нашей системы, я использую две петли для итерации обоих наборов данных, но не могу получить правильные координаты для заполнения в большем массиве данных. Более конкретно, единственная координатная пара, которая вытягивается и заполняется в массиве информации о компании, является самой последней парой на итерации [132].
Вот фрагмент кода:
if ($ticket_number = $onsites) {
$current_onsites = array();
$i = 0;
$coordinates = json_decode(file_get_contents('geo.json'), true);
$crd = array();
for ($i = 0; $i <= count($ticket_number); $i++) {
@$current_onsites[$i]['id'] = $ticket_number[$i];
@$current_onsites[$i]['text'] = $summary[$i];
@$current_onsites[$i]['location'] = $location[$i];
@$current_onsites[$i]['company'] = $company[$i];
@$current_onsites[$i]['site'] = $site[$i];
@$current_onsites[$i]['location'] = $full_address[$i];
@$current_onsites[$i]['contact'] = $contact[$i];
@$current_onsites[$i]['start_date'] = date('Y-m-d H:i:s', strtotime($startDate[$i]));
@$current_onsites[$i]['end_date'] = date('Y-m-d H:i:s', strtotime($endDate[$i]));
@$current_onsites[$i]['technician'] = $technician[$i];
@$current_onsites[$i]['hours'] = $hours[$i];
@$current_onsites[$i]['status'] = $status[$i];
@$current_onsites[$i]['ownerFlag'] = $ownerFlag[$i];
foreach ($coordinates as $latlng){
if ($latlng['input_id'] = @$current_onsites[$i]['company']) {
@$current_onsites[$i]['lat'] = $latlng['metadata']['latitude'];
@$current_onsites[$i]['lng'] = $latlng['metadata']['longitude'];
} else {}
}
}
print "<pre>";
print_r ($current_onsites);
print "</pre>";
//$fp = fopen('results.json', 'w');
//fwrite($fp, json_encode($current_onsites));
//fclose($fp);
Я знаю, что код довольно грязный, я просто ищу, чтобы он работает на данный момент. Любые идеи приветствуются. Благодарю.