1) { $into = $merging; uasort($into, function ($a, $b) use ($used) { return $used($b['category_id']) <=> $used($a['category_id']) ?: strnatcasecmp($a['category_name'], $b['category_name']); }); } foreach (categoryRows($config['kind']) as $category_id => $row) { if (!isset($merging[$category_id]) && !$row['category_archived_at']) { $into[$category_id] = $row; } } } $keep_id = count($merging) > 1 ? intval(array_key_first($into)) : 0; // What merging does, in words $one = count($merging) === 1; $records = 0; foreach ($merging as $merge_id => $row) { $records += $used($merge_id); } $merge_text = ''; if ($config) { $merge_text = ($records ? 'The ' . number_format($records) . ' ' . ($records === 1 ? 'record' : 'records') . ' with ' . ($one ? 'it get' : 'these get') . ' the ' . $config['one'] . ' you keep instead' . ($config['by'] === 'name' ? ' - renamed to it' : '') . ($config['kind'] === 'Expense' ? ', and a month budgeted under more than one ends with one line of their total' : '') . '.' : 'Nothing uses ' . ($one ? 'it' : 'these') . ' yet.') . ($one ? ' It is then deleted.' : ' The others are then deleted.') . " This can't be undone."; } ob_start(); ?>