How can a button in PHP be inserted to execute a function in the same document?

To insert a button in PHP that executes a function in the same document, you can use a form with a submit button. The button can trigger the function by submitting the form to the same PHP file and checking for the form submission. Once the form is submitted, you can call the desired function based on the button click.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (isset($_POST['submit_button'])) {
        // Call the function here
        yourFunction();
    }
}

function yourFunction() {
    // Your function code here
}

?>

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