(вчера прислали горящие правки, сейчас только закончил):
if (isset($future_events) || isset($past_events)) {
$future_e_count = count($future_events);
$past_e_count = count($past_events);
$count = ($future_e_count + $past_e_count) < 6 ? ($future_e_count + $past_e_count) : 6;
if ($future_e_count < $count) {
$events_in_list = array_slice($future_events, 0, $future_e_count, true);
} else if ($future_e_count >= 6) {
$events_in_list = array_slice($future_events, 0, 6, true);
}
$count_events = count($events_in_list);
if ($count_events < 6) {
foreach (array_slice($past_events, -$past_e_count, 6 - $count_events, true) as $key => $value) {
$events_in_list[$key] = $value;
}
}
}
Аж глаз задергался.
Возможно я не прав, но код можно сократить до if (isset($future_events) || isset($past_events)) { $events_in_list = array_slice($future_events, 0, 6, true); $count_events = count($events_in_list); if ($count_events < 6) { $past_e_count = count($past_events); $events_in_list = array_merge( $events_in_list, array_slice($past_events, -$past_e_count, 6 - $count_events, true) } }
Обсуждают сегодня