Reputation: 1
I have an array containing current ticket info as follows:
[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...
I also have another array from which the company location coordinates are being pulled from:
[0] => Array
(
[company] => Rhodes and Associates
[lat] => 47.32026
[lng] => -122.30402
)
[1] => Array //There are 130+ more...
After pulling the ticket data (cURL) from our system, I'm using two loops to iterate through both data sets but can't seem to get the correct coordinates to populate in the larger data array. More specifically, the only coordinate pair being pulled and populating in the company info array is the very last pair in the iteration, [132].
Here is a code snippet:
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);
I know the code is quite dirty, I'm just looking to get it working for now. Any ideas are greatly appreciated. Thanks.
Upvotes: 0
Views: 148
Reputation: 283093
if ($latlng['input_id'] = @$current_onsites[$i]['company']) {
You've got a single =
there -- that's assignment, not comparison.
But you shouldn't be doing it that way anyway. Two loops turns your O(n) algorithm into O(n^2). Re-index the second array by company name so that you can perform quick lookups.
Upvotes: 1