Php 如何使用Google analytics Restful获取访问者数量

Php 如何使用Google analytics Restful获取访问者数量,php,arrays,Php,Arrays,如您所见,有没有办法避免我的代码中重复链接 $gaUrl['devices'] = "&start-date=$this->startdate&end-date=$this->enddate&metrics=".$gaQuery['devices']['metrics']."&dimensions=".$gaQuery['devices']['dimensions']."&sort=".$gaQuery['devices']['sort'];

如您所见,有没有办法避免我的代码中重复链接

$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'];

我认为你应该用一个变量替换链接

$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'];