Calculate BMI(Body Mass Index) using PHP program

BMI calculator:

Body mass index (BMI) is a measure of body fat based on height and weight that applies to adult men and women.

Formula for BMI :

BMI Categories:

Underweight = <18.5
Normal weight = 18.5–24.9 
Overweight = 25–29.9 
Obesity = BMI of 30 or greater

Input to the program is height and weight in JSON

PHP program to calculate BMI:

The JSON string contains the height in centimeters and weight in Kgs. The json_decode function is used in the program to converts the JSON string to PHP array.The height and weight variables gets the corresponding value from the array.

The height is divided by 100 that converts the value from centimeters to meters.Then we are applying BMI formula to get the BMI categories.Finally we are validating the BMI value and returns the corresponding message as a output.The json_encode function is used in the last step to converts the PHP array to JSON string.

Output :