function tom_validate_options($input) { if (isset($_POST['reset'])) { add_settings_error('tonjoo-tom', 'restore_defaults', 'Default options restored.', 'updated fade'); return TOMOption::tom_get_default_values(); } foreach ($input as $key => $value) { // $value['options'] = array(); $haveoptions = array(); if (!empty($value['options']) && is_array($value['options'])) { /* combine input value key and input value to one array as key => value */ $combine[$key]['options'] = array_combine($value['options']['opt-key'], $value['options']['opt-val']); /* get other field like name, type */ $org[$key] = $value; /* Merge options field */ $haveoptions[$key] = array_merge($org[$key], $combine[$key]); } $input = array_merge($input, $haveoptions); } /* Merge with main input */ $input = array_merge($input, $haveoptions); return json_encode($input); }