2017-01-18 19 views
1

私は、PHPファイルを持って、私は以下に示すように、2-の配列を返す関数log_campaign_activityを、定義したA.phpを、言う:PHP 5.6の関数から複数の配列を呼び出す方法は?

function log_campaign_activity($identifier, $activity, $update=true, $clicked_url_key=null) { 

$return_array = array(); 

$db = DBManagerFactory::getInstance(); 



//check to see if the identifier has been replaced with Banner string 
if($identifier == 'BANNER' && isset($clicked_url_key) && !empty($clicked_url_key)) 
{ 
    // create md5 encrypted string using the client ip, this will be used for tracker id purposes 
    $enc_id = 'BNR'.md5($_SERVER['REMOTE_ADDR']); 

    //default the identifier to ip address 
    $identifier = $enc_id; 

    //if user has chosen to not use this mode of id generation, then replace identifier with plain guid. 
    //difference is that guid will generate a new campaign log for EACH CLICK!! 
    //encrypted generation will generate 1 campaign log and update the hit counter for each click 
    if(isset($sugar_config['campaign_banner_id_generation']) && $sugar_config['campaign_banner_id_generation'] != 'md5'){ 
     $identifier = create_guid(); 
    } 

    //retrieve campaign log. 
    $trkr_query = "select * from campaign_log where target_tracker_key='$identifier' and related_id = '$clicked_url_key'"; 
    $current_trkr=$db->query($trkr_query); 
    $row=$db->fetchByAssoc($current_trkr); 

    //if campaign log is not retrieved (this is a new ip address or we have chosen to create 
    //unique entries for each click 
    if($row==null || empty($row)){ 


      //retrieve campaign id 
      $trkr_query = "select ct.campaign_id from campaign_trkrs ct, campaigns c where c.id = ct.campaign_id and ct.id = '$clicked_url_key'"; 
      $current_trkr=$db->query($trkr_query); 
      $row=$db->fetchByAssoc($current_trkr); 


      //create new campaign log with minimal info. Note that we are creating new unique id 
      //as target id, since we do not link banner/web campaigns to any users 

      $data['target_id']="'" . create_guid() . "'"; 
      $data['target_type']= "'Prospects'"; 
      $data['id']="'" . create_guid() . "'"; 
      $data['campaign_id']="'" . $row['campaign_id'] . "'"; 
      $data['target_tracker_key']="'" . $identifier . "'"; 
      $data['activity_type']="'" . $activity . "'"; 
      $data['activity_date']="'" . TimeDate::getInstance()->nowDb() . "'"; 
      $data['hits']=1; 
      $data['deleted']=0; 
      if (!empty($clicked_url_key)) { 
       $data['related_id']="'".$clicked_url_key."'"; 
       $data['related_type']="'".'CampaignTrackers'."'"; 
      } 

      //values for return array.. 
      $return_array['target_id']=$data['target_id']; 
      $return_array['target_type']=$data['target_type']; 

      //create insert query for new campaign log 
      $insert_query="INSERT into campaign_log (" . implode(",",array_keys($data)) . ")"; 
      $insert_query.=" VALUES (" . implode(",",array_values($data)) . ")"; 
      $db->query($insert_query); 
     }else{ 

      //campaign log already exists, so just set the return array and update hits column 
      $return_array['target_id']= $row['target_id']; 
      $return_array['target_type']= $row['target_type']; 
      $query1="update campaign_log set hits=hits+1 where id='{$row['id']}'"; 
      $current=$db->query($query1); 


     } 

    //return array and exit 
    return $return_array; 

} 

あなたは最終的に、それが戻っていることを観察することができます2配列:

  • $ return_array ['target_id'] = $ row ['target_id'];
  • $ return_array ['target_type'] = $ row ['target_type'];

    • $ targetIDの
    • $たtargetType

私はこの関数を呼び出すと、別のphpファイルの2変数でこれらの値を格納したい、B.php言いますこれどうやってするの?より良い方法は何ですか?おかげで

RK

答えて

0

B.php

//Require A.php, so you can call your function 
require_once("A.php"); 

//Call your function with needed parameters 
$result = log_campaign_activity($param1, $param2, $param3...); 

//Save result into vars 
$targetID = $result["target_id"]; 
$targetType = $result["target_type"]; 
関連する問題