How can variables be passed to a PHP script to call a specific function based on user input?
To pass variables to a PHP script to call a specific function based on user input, you can use conditional statements to check the user input and then call the corresponding function. You can use GET or POST parameters to pass the user input to the PHP script.
<?php
// Get the user input
$user_input = $_GET['input'];
// Check the user input and call the corresponding function
if ($user_input == 'function1') {
function1();
} elseif ($user_input == 'function2') {
function2();
}
// Define the functions
function function1() {
// Function 1 code here
}
function function2() {
// Function 2 code here
}
?>