好的我有一个嵌套数组,它返回对象,然后遍历这些对象,然后用它来检索另一个被遍历的数组,返回的值被回显出问题,这似乎需要花费很长时间才能完成。我怎么去加速这个? 代码如下: 这是第一个功能:
/**
* Get a page of Campaigns
* @param string $page - url to page of campaigns, default is first page
* @return array - array of Campaign objects and a link to the next page if one exists
*/
public function getCampaigns($page=null){
$page = ($page) ? $this->CTCTRequest->baseUri.$page : $this->uri;
$campaignsCollection = array('campaigns' => array(), 'nextLink' => '');
$response = $this->CTCTRequest->makeRequest($page, 'GET');
$parsedResponse = simplexml_load_string($response['xml']);
foreach ($parsedResponse->entry as $entry){
$campaignsCollection['campaigns'][] = new Campaign(Campaign::createOverviewStruct($entry));
}
$campaignsCollection['nextLink'] = Utility::findNextLink($parsedResponse);
return $campaignsCollection;
}
这是第二个功能:
/**
* Get detailed Campaign object
* @param string $url - url of a Campiagn
* @return Campaign
*/
public function getCampaignDetails($url){
$response = $this->CTCTRequest->makeRequest($url, 'GET');
$parsedReturn = simplexml_load_string($response['xml']);
return new Campaign(Campaign::createStruct($parsedReturn));
}
这是遍历这两个并返回我的值的代码:
<?php
/*
*
*
*grab the Campaign array
*
*
*/
$getallCampaigns = $ConstantContact->getCampaigns(false);
?>
<table class="CTCTtable">
<tr>
<th>Campaign Name</th>
<th>Date</th>
<th>Status</th>
<th>Sent#</th>
<th>Opens</th>
<th>Clicks</th>
<th>Bounces</th>
<th>Forwards</th>
<th>OptOuts</th>
<th>SpamReports</th>
</tr>
<?php
foreach ($getallCampaigns as $tableName => $tableData) { // Loop outer array
foreach ($tableData as $row) { // Loop table rows
$originalDate = $row->campaignDate;
$newDate = date("d-m-Y", strtotime($originalDate));
//get campaign details
$getallCampaignevents = $ConstantContact->getCampaignDetails($row);
//$getallCampaignsends = $ConstantContact->getCampaignSends($row);
//
//echo $getallCampaignevents->name;
echo '<tr>';
echo '<td><a title="'.$getallCampaignevents->name.'"href="'.$getallCampaignevents->id.'">'.$getallCampaignevents->name.'</a></td>';
echo '<td>'.$newDate.'</td>';
echo '<td>'.$getallCampaignevents->status.'</td>';
echo '<td>'.$getallCampaignevents->campaignSent.'</td>';
echo '<td>'.$getallCampaignevents->campaignOpens.'</td>';
echo '<td>'.$getallCampaignevents->campaignClicks.'</td>';
echo '<td>'.$getallCampaignevents->campaignBounces.'</td>';
echo '<td>'.$getallCampaignevents->campaignForwards.'</td>';
echo '<td>'.$getallCampaignevents->campaignOptOuts.'</td>';
echo '<td>'.$getallCampaignevents->campaignSpamReports.'</td>';
echo '</tr>';
// var_dump($getallCampaignevents);
}
}
?>
</table>
这是第一个返回的数组的示例:
array(2) {
["campaigns"]=>
array(50) {
[0]=>
object(Campaign)#68 (48) {
["name"]=>
string(26) "*****************************"
["id"]=>
string(74) "***********************************************"
["link"]=>
string(44) "************************"
["status"]=>
string(4) "Sent"
["campaignDate"]=>
string(24) "2013-12-05T21:28:07.330Z"
["urls"]=>
array(0) {
}
}
[1]=>
object(Campaign)#68 (48) {
["name"]=>
string(26) "*****************************"
["id"]=>
string(74) "***********************************************"
["link"]=>
string(44) "************************"
["status"]=>
string(4) "Sent"
["campaignDate"]=>
string(24) "2013-12-05T21:28:07.330Z"
["urls"]=>
array(0) {
}
}
}
这是第二个returend数组:
object(Campaign)#64 (48) {
["name"]=>
string(26) "*************"
["id"]=>
string(74) "***************"
["link"]=>
string(44) "************************"
["status"]=>
string(4) "Sent"
["campaignDate"]=>
string(24) "2013-12-05T21:28:07.330Z"
["lastEditDate"]=>
string(24) "2013-12-02T14:52:13.629Z"
["lastRunDate"]=>
string(24) "2013-12-05T21:28:07.327Z"
["campaignSent"]=>
string(2) "13"
["campaignOpens"]=>
string(1) "8"
["campaignClicks"]=>
string(1) "5"
["campaignBounces"]=>
string(1) "0"
["campaignForwards"]=>
string(1) "0"
["campaignOptOuts"]=>
string(0) ""
["campaignSpamReports"]=>
string(0) ""
["subject"]=>
string(33) "Offers, and your feedback please!"
["fromName"]=>
string(18) "***************"
["campaignType"]=>
string(5) "STOCK"
["hiveStatus"]=>
string(0) ""
["archiveUrl"]=>
string(0) ""
}
object(Campaign)#56 (56) {
["name"]=>
string(26) "*************"
["id"]=>
string(74) "***************"
["link"]=>
string(44) "************************"
["status"]=>
string(4) "Sent"
["campaignDate"]=>
string(24) "2013-12-05T21:28:07.330Z"
["lastEditDate"]=>
string(24) "2013-12-02T14:52:13.629Z"
["lastRunDate"]=>
string(24) "2013-12-05T21:28:07.327Z"
["campaignSent"]=>
string(2) "13"
["campaignOpens"]=>
string(1) "8"
["campaignClicks"]=>
string(1) "5"
["campaignBounces"]=>
string(1) "0"
["campaignForwards"]=>
string(1) "0"
["campaignOptOuts"]=>
string(0) ""
["campaignSpamReports"]=>
string(0) ""
["subject"]=>
string(33) ""
["fromName"]=>
string(18) "***************"
["campaignType"]=>
string(5) "STOCK"
["hiveStatus"]=>
string(0) ""
["archiveUrl"]=>
string(0) ""
}
我正在使用Constant Contact的OAuth API和这个php包装器来返回这些数组: it can be found here