This question probably belongs to Code Review.
Anyway, you can fill your event properties inside an array, which you can iterate:
$events = array(
'opening' => array(
'time' => '...time here...',
'formatted_time' => '...time here...',
'label' => __('Opening:'), // or ucfirst($type) if you want...
),
'closing' => array(
'time' => '...time here...',
'formatted_time' => '...time here...',
'label' => __('Clsoing:'),
),
'artist_talk' => array(
'time' => '...time here...',
'formatted_time' => '...time here...',
'label' => __('Artist Talk:'),
),
// and so on...
);
foreach($events as $type => $properties){
if($properties['time'] >= $today) {
echo '<h5>';
if ($properties['time'] <= $todayevening) {
echo '<span class="last_chance">Today: </span>';
}
elseif ($properties['time'] > $todayevening && $properties['time'] <= $tonight) {
echo '<span class="last_chance">Tonight: </span>';
}
elseif ($properties['time'] > $tonight && $properties['time'] <= $tomorrow) {
echo '<span class="last_chance">Tomorrow: </span>';
}
echo '<span class="strong">'.$properties['label'].' </span>'.$properties['formatted_time'] .'</h5>';
}
}