How can PHP functions be used effectively to calculate BMI in a web application?

To calculate BMI in a web application using PHP functions, you can create a function that takes in the weight and height as parameters, calculates the BMI using the formula (BMI = weight / (height * height)), and returns the result. This function can then be called wherever needed in your web application to calculate BMI efficiently.

function calculateBMI($weight, $height) {
    $bmi = $weight / ($height * $height);
    return $bmi;
}

// Example usage
$weight = 70; // in kilograms
$height = 1.75; // in meters
$bmi = calculateBMI($weight, $height);
echo "Your BMI is: " . $bmi;