public static function merge($default_params, $input_params) { foreach ($default_params as $key => $value) { if (empty($input_params[$key])) { continue; } else { $value = $input_params[$key]; } switch ($key) { case "min_price": if (Number::isNatural($value)) { $default_params[$key] = $value; } break; case "max_price": if (Number::isNatural($value)) { $default_params[$key] = $value; } break; case "page": if (Number::isNatural($value)) { $default_params[$key] = $value; } break; case "limit": if (Number::isNatural($value) && $value < MAX_LIMIT) { $default_params[$key] = $value; } break; case "sort": if ($value == "+price" || $value == "+id" || $value == "-price" || $value == "-id") { $default_params[$key] = $value; } break; case "category_id": if (Number::isNatural($value)) { $default_params[$key] = $value; } break; case "id": if (Number::isNatural($value)) { $default_params[$key] = $value; } break; case "keyword": $default_params[$key] = $value; break; default: // other params will be dropped.. break; } } return $default_params; }