Putting an Array into a table split In PHP, I'm getting multiple series and dumping various bits of information into an array. I will be left with 180 items (if I put in 30 series details that have 6 events per series)

$eventsArray = explode(',', $events); // This gets passed in via a param
\load_curl();
$array = Array();
$curl_array = array();

$ch = curl_multi_init();
foreach($eventsArray as $count =&gt; $id) {
    $curl_array[$count] = curl_init("https://www.eventbriteapi.com/v3/series/".$id."/events/?expand=ticket_classes&amp;token=XXX");
    curl_setopt($curl_array[$count], CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl_array[$count], CURLOPT_VERBOSE, true);
    curl_setopt($curl_array[$count], CURLOPT_SSL_VERIFYPEER, false);
    curl_multi_add_handle($ch, $curl_array[$count]);
}

do {
    curl_multi_exec($ch, $exec);
} while($exec &gt; 0);

foreach($eventsArray as $count =&gt; $id) {
    $returned = curl_multi_getcontent($curl_array[$count]);
    $json = \json_decode($returned,true);
    foreach ( $json["events"] as $event) {
        $remaining = $event["ticket_classes"][0]["quantity_total"] - $event["ticket_classes"][0]["quantity_sold"];
        $array[] = Array('id'=&gt;$event["id"],
                         'url'=&gt;$event["url"],
                         'status'=&gt;$event["status"],
                         'remaining'=&gt;$remaining,
                         'start'=&gt;date('l, jS F Y', strtotime($event["start"]["local"]))
                   );
    }
}

foreach($eventsArray as $count =&gt; $id) {
    curl_multi_remove_handle($ch, $curl_array[$count]);
}

curl_multi_close($ch); 

foreach($eventsArray as $count =&gt; $id) {
    curl_close($curl_array[$count]);
}

$array = array_chunk($array, 30);
$array = json_encode($array);
return $array;


I then use EJS to display the information like below. The first item in each chunk is displayed in a row, then second item of each chunk in the next row etc.

&lt;% for(var i=0; i&lt;30; i++) { %&gt;
    &lt;tr&gt;
        &lt;th&gt;&lt;%= this[0][i]['start'] %&gt;&lt;/th&gt;
    &lt;% for (var x=0; x&lt;6; x++) { 

    if (this[x][i]['status'] == 'live') {
        if (this[x][i]['remaining']&lt;=0) {
            status='&lt;span class="badge"&gt;FULL&lt;/span&gt;'; 
            style = 'class="danger"';
        }
        else {
            status ='&lt;a href="'+ this[x][i]['url'] +'"&gt;Book now&lt;/a&gt;&lt;br&gt;&lt;span class="badge badge-success"&gt;'+this[x][i]['remaining']+' AVAILABLE&lt;/span&gt;'; 
            style = 'class="success"';
        }
    }
    else {
            status='&lt;span class="badge"&gt;COMPLETE&lt;/span&gt;'; 
            style = 'class="warning"';
    }

    %&gt;
        &lt;td &lt;%=style%&gt;&gt; &lt;%=status%&gt;&lt;/td&gt;
    &lt;% } %&gt;
    &lt;/tr&gt;
&lt;% } %&gt;


It works but takes about 5 seconds to run. What could I do to make it faster? Is there much improvement that could be made?
Use a local database to store information

You could start by testing what takes the longest, and concentrate your efforts there. I cannot do this test. However, getting multiple bits of information, from an external API, can never be quick. This is probably what is slowing you down.

The API is: https://www.eventbrite.com/developer/v3

I had a very short look at the API you're using, and quickly stopped when I noticed it was quite complex. :-)

Do you retrieve information from the API for every page you render? Does this mean that the same information is requested from the API several times?

In that case it would be better to store the retrieved information in a local database, and use the information from your local database to build the web pages.

The API has webhooks. These can be useful to update the information in your database. Use them.

I know this isn't really an answer that reviews your code.