Hello!

I've been handed a bit of code which displays an event calendar. Each event has a title, start time, end time, and a description. The goal is for each title to be a button which will toggle to show that event's description. So far, I have it set up so that all titles have a button. However, they're all tied to the first event's description! From my research, I think what I need is a for/while loop to go through each event and give each event's description a custom anchor tag.

Any tips on where the while/loop should go in the output?

Code:
 
public function event_block($title, $desc, $start, $end, $where = NULL, $img = NULL, $span = 6)
  {
    $start_arr = date_parse($start);
    $start_stamp = mktime($start_arr['hour'], $start_arr['minute'], $start_arr['second'], $start_arr['month'], $start_arr['day'], $start_arr['year']);
    $start_date_int = date('Ymd', $start_stamp);
    
    $end_arr = date_parse($end);
    $end_stamp = mktime($end_arr['hour'], $end_arr['minute'], $end_arr['second'], $end_arr['month'], $end_arr['day'], $end_arr['year']);
    $end_date_int = date('Ymd', $end_stamp);

    $today_date_int = date('Ymd');
    
    $time_range = date('g:i a', $start_stamp) . ' to ' . date('g:i a', $end_stamp);
    
    
    if ($start_date_int == $today_date_int) {
      $date = 'Today';
      if ($start_date_int < $end_date_int) {
        $time_range = 'Until ' . date('l, F jS', $end_stamp);
      }
    } else {
      $date = date('l, F jS', $start_stamp);
      if ($start_date_int < $end_date_int) {
        $time_range = 'From' . date('l, F jS', $start_stamp) . ' through ' . date('l, F jS', $end_stamp);
      }
    }
    
    
    $output = '

        <!-- Event Block -->
        <div class="span' . $span . ' event">
        <div class="panel-group id="accordion">
          <div class="panel-heading">
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" class="btn btn-primary btn-lg">' . $title . '</a>';

    if (trim($desc) && $date == 'Today') {
      $output .=  '<div id="collapseOne" class="panel-collapse collapse in">
            <div class="panel-body">' .  trim($desc) .  '</div>';
    }
    $output .= '<p style="padding-left: 5px;">';
    if ($date != 'Today') {
      $output .= '<span style="color: #E8D0A9;">Date:</span> ' . $date . '<br />';
    }
    $output .= '<span style="color: #E8D0A9;">Time:</span> ' . $time_range . '</p></div>';
        
    return $output;

  }