0

2 つの異なるシステムから作成した 2 つのアレイがあります。

URL が変更されました

左側の配列をループして、ビジネス、住所、郵便番号に一致するものを見つける必要があります。右側に一致するものがあれば、それを取得idして左側の配列項目に追加する必要があります。

必要に応じて変更できるように、配列を構造化しています。

${'URL'} = 'http://reviewsfor.biz/api/biz/';

    // Initiate the cURL request
    $curl = curl_init();

    $data = array(
                    'api_key' => REVIEWS_API_KEY,
                    'format' => 'json',
                    'act' => 'active'
                   );

    // Set the cURL options
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_TIMEOUT, 5);
    curl_setopt($curl, CURLOPT_URL, ${'URL'}.'?'.http_build_query($data)); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    // Execute the cURL POST        
    $response = curl_exec($curl);

    // Close the cURL connection
    curl_close($curl);

    $response = json_decode($response);

    // Out the list of businesses into an array
    ${'Business List'} = $response->businesses;
    ${'Local Biz Array'} = array();
    ${'Query'} = mysql_query('SELECT * FROM `companies`.`subdomains`');
    while(${'Sub Domain'} = mysql_fetch_assoc(${'Query'})){

        ${'Database'} = ${'Sub Domain'}['database'];
        ${'DB Query'} = mysql_query('SELECT * FROM `'.${'Database'}.'`.`users`');

        while(${'User'} = mysql_fetch_assoc(${'DB Query'})){
            if(${'User'}['company'] != ''){
                ${'Local Biz Array'}[] = array('business' => ${'User'}['company'], 'address' => ${'User'}['company_address'], 'zip' => ${'User'}['company_zip'], 'user_id' => ${'User'}['id']);
            }
        }

    }
    // Build an array
    ${'LBL Biz Array'} = array();
    foreach(${'Business List'} as $item){
        ${'LBL Biz Array'}[] = array('business' => $item->business->business, 'address' => $item->business->address, 'zip' => $item->business->zip, 'id' => $item->business->id);
    }


    echo '<div id="leftCol" style="float:left;width:49%;height:500px;overflow:scroll;">';
    echo '<pre>';
    print_r(${'LBL Biz Array'});
    echo '</pre></div>';

    echo '<div id="rightCol" style="float:right;width:49%;height:500px;overflow:scroll;">';
    echo '<pre>';
    print_r(${'Local Biz Array'});
    echo '</pre></div>';
4

1 に答える 1

0
function findMatch($arrayLeft, $arrayRight){
   for($i=0,$j=count($arrayLeft);$i<$j;$i++){
      for($k=0,$l=count($arrayRight);$k<$l; $k++){
         if($arrayLeft[$i]['business'] == $arrayRight[$k]['business'] && $arrayLeft[$i]['address'] == $arrayRight[$k]['address'] && $arrayLeft[$i]['zip'] == $arrayRight[$k]['zip']){
            $arrayLeft[$i]['user_id'] = $arrayRight[$k]['user_id'];
            unset($arrayRight[$k]); //remove addresses already matched
            break;      
         }     
      }
   }
   return $arrayLeft;
}
于 2013-05-15T23:28:21.327 に答える