有没有办法避免代码中的链接重复,正如您所看到的那样
$gaUrl['devices'] = "&start-date=$this->startdate&end-date=$this->enddate&metrics=".$gaQuery['devices']['metrics']."&dimensions=".$gaQuery['devices']['dimensions']."&sort=".$gaQuery['devices']['sort'];
$gaUrl['keywords'] = "&start-date=$this->startdate&end-date=$this->enddate&metrics=".$gaQuery['keywords']['metrics']."&dimensions=".$gaQuery['keywords']['dimensions']."&sort=".$gaQuery['keywords']['sort'];
$gaUrl['countries'] = "&start-date=$this->startdate&end-date=$this->enddate&metrics=".$gaQuery['countries']['metrics']."&dimensions=".$gaQuery['countries']['dimensions']."&sort=".$gaQuery['countries']['sort'];
$gaUrl['destinations'] = "&start-date=$this->startdate&end-date=$this->enddate&metrics=".$gaQuery['destinations']['metrics']."&dimensions=".$gaQuery['destinations']['dimensions']."&sort=".$gaQuery['destinations']['sort'];
$gaUrl['currentTrafficSrc'] = "&start-date=$this->startdate&end-date=$this->enddate&metrics=".$gaQuery['currentTrafficSrc']['metrics']."&dimensions=".$gaQuery['currentTrafficSrc']['dimensions']."&sort=".$gaQuery['currentTrafficSrc']['sort'];
// Visits
$gaUrl['cuurentMonthVisits'] = "&start-date=$this->startdate&end-date=$this->enddate&metrics=".$gaQuery['cuurentMonthVisits']['metrics'];
$gaUrl['lastMonth'] = "&start-date=$this->startdate&end-date=$this->enddate&metrics=".$gaQuery['cuurentMonthVisits']['metrics'];
答案 0 :(得分:0)
我认为你应该用变量替换链接
$l = "&start-date=$this->startdate&end-date=$this->enddate&metrics=";
$gaUrl['devices'] = $l.$gaQuery['devices']['metrics']."&dimensions=".$gaQuery['devices']['dimensions']."&sort=".$gaQuery['devices']['sort'];
$gaUrl['keywords'] = $l.$gaQuery['keywords']['metrics']."&dimensions=".$gaQuery['keywords']['dimensions']."&sort=".$gaQuery['keywords']['sort'];