Is there a more efficient way to sanitize and validate multiple variables passed through POST in PHP?

When sanitizing and validating multiple variables passed through POST in PHP, it is more efficient to use an array to store the variables and loop through them to apply the sanitization and validation functions. This approach reduces code duplication and makes it easier to manage multiple variables.

// Array to store POST variables
$post_data = $_POST;

// Array to store sanitized data
$sanitized_data = array();

// Loop through each POST variable to sanitize and validate
foreach ($post_data as $key => $value) {
    // Sanitize and validate the value
    $sanitized_data[$key] = filter_var($value, FILTER_SANITIZE_STRING);
}

// Use the sanitized data for further processing
// Example: $sanitized_data['variable_name']