How can PHP be used to execute a function upon clicking a button and reloading the page?

To execute a function upon clicking a button and reloading the page using PHP, you can create a form with a submit button that triggers the function upon submission. In the PHP code, you can check if the form has been submitted and then execute the desired function before reloading the page.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Check if the form is submitted
    // Execute the function here
    
    // Reload the page
    header("Location: ".$_SERVER['PHP_SELF']);
    exit();
}
?>

<form method="post">
    <button type="submit" name="submit">Click me</button>
</form>