0

我有以下 php 代码:

// Add the unsubscribers to an array
$unsubs = array();
foreach($unsubscribers->response->Results as $entry2) {
    $unsubs[] = $entry2->EmailAddress;
}

// Loop through the subscribers
foreach($result->response->Results as $entry) { 

    echo '<tr class="'. $entry->EmailAddress.'">';      
    echo '<td>'. $entry->EmailAddress.'</td>';
    echo '<td></td><td>';

    // If the subscriber is in our unsubscriber array, output the email again
    if(in_array($entry->EmailAddress, $unsubs)) { 
        echo $entry->EmailAddress;
    }

    echo '</td><td></td>';
    echo '<td></td>';
    echo '<td></td>';
    echo '</tr>';

}

<td></td>的位置我想放置以下内容:

$getlists = new CS_REST_Campaigns($_POST['campaign_id'], $auth);
$getlistsresult = $wrap->get_lists_and_segments();
    foreach($getlistsresult->response->Lists as $list) {
        //echo $list->ListID;
    } 

$wrapcount = new CS_REST_Subscribers($list->ListID, $auth);
$resultcount = $wrapcount->get_history($entry->EmailAddress);   


    foreach($resultcount->response as $entrycount) { 

        $counts = array();

foreach($entrycount->Actions as $actions) {
    if(!isset($counts[$actions->Event])) {
        $counts[$actions->Event] = 0;
    }
    ++$counts[$actions->Event];
}


    echo '<td>';
    if ($counts['Click']){echo $counts['Click'];} 
    echo '</td>';

    echo '<td>';
    if ($counts['Bounce']){echo 'Yes';}
    echo '</td>';

    echo '<td>';
    if ($counts['Open']){echo $counts['Open'];} 
    echo '</td>';

    }

这在一定程度上有效,但页面的加载时间显着增加。老实说,我认为我的代码需要整理。关于如何加快速度的任何建议?

4

1 回答 1

1

在您的代码中,我看不到太多明显未优化的内容,有一些我不知道的函数调用来自您的 CS_REST 类,但我们不知道这些函数的作用,也不知道它们是否会变慢或优化。

有了这些信息,我能看到的唯一可能对您有所帮助的是使用SplFixedArray类。如果您的数组中有很多条目并对它们执行大量操作,这将非常有用。基本上,它们类似于真正的数组,因为它们的索引总是一个整数并且它们具有固定的大小,这反过来又使它们使用起来更快。

于 2013-07-17T14:31:00.470 回答