How can the EVA (Extract, Validate, Apply) principle be applied to refactor PHP code that mixes database queries with HTML output?

Issue: The mixing of database queries with HTML output in PHP code makes the code difficult to maintain and test. To refactor this code, we can apply the EVA principle by extracting the database queries into separate functions, validating the data retrieved from the database, and then applying the data to the HTML output. PHP Code Snippet:

<?php
// Extract: Database queries are extracted into separate functions
function get_user_data($user_id) {
    // Database query to retrieve user data
    return $user_data;
}

// Validate: Validate the data retrieved from the database
$user_id = 1;
$user_data = get_user_data($user_id);

if ($user_data) {
    // Apply: Apply the data to the HTML output
    echo "<h1>Welcome, " . $user_data['username'] . "</h1>";
    echo "<p>Email: " . $user_data['email'] . "</p>";
} else {
    echo "User not found.";
}
?>