The code works perfect, but since I’m repeating myself (which I like to avoid while programming), I was wondering if this could be written any shorter/better?
$start = getLocaleDate($item[0]['start_day']);
$start = $start['day_int'] . ' ' . $start['month_string'];
if ($item[0]['start_houre'] !== '00:00:00') {
$houre = stripLeadingZero(substr($item[0]['start_houre'], 0, 2));
$minute = substr($item[0]['start_houre'], 3, 2);
$start .= ' at' . $houre . 'u' . $minute;
}
$end = getLocaleDate($item[0]['end_day']);
$end = $end['day_int'] . ' ' . $end['month_string'];
if ($item[0]['end_houre'] !== '00:00:00') {
$houre = stripLeadingZero(substr($item[0]['end_houre'], 0, 2));
$minute = substr($item[0]['end_houre'], 3, 2);
$end .= ' at' . $houre . 'u' . $minute;
}
Without changing any of the functionality, you could make it into a function:
* It should be noted that this code doesn’t do any error checking/prevention though, so if there is no index
0in the$item, you will have an error (same goes for$item[0]['start_day'],$item[0]['end_day'], etc). To handle a simple-case, you could addif (!isset($item[0])) return '';to the beginning of the function, if it’s a concern.