0
我有一個包含當前票據信息的排列如下: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);
我知道代碼是相當髒,我只是希望得到它的工作現在。任何想法,不勝感激。謝謝。