How can variables be used as parameters in a PHP function?

To use variables as parameters in a PHP function, you simply need to define the function with the variable names as parameters. When calling the function, you pass the variables as arguments. This allows you to reuse the same function with different values by passing different variables each time.

// Define a function that takes two variables as parameters
function addNumbers($num1, $num2) {
    return $num1 + $num2;
}

// Use the function with variables as arguments
$a = 5;
$b = 10;
$result = addNumbers($a, $b);

echo $result; // Output: 15