foreach ($database['defense'] as $code) {
if (isset($data[$code])) {
$fields .= ', ' . $code;
$set .= ', ' . (int)$data[$code];
}
}
foreach ($database['defense'] as $code) {
if (isset($data['defense'][$code])) {
$fields .= ', ' . $code;
$set .= ', ' . (int)$data['defense'][$code];
}
}