-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBMI.php
34 lines (34 loc) · 1014 Bytes
/
BMI.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
class BMI
{
function index($height = 162.6, $weight = 84)
{
$result = new stdClass();
$cm = $height;
$kg = $weight;
$meter = $cm / 100;
$inches = $meter * 39.3700787;
$feet = round($inches / 12);
$inches = $inches % 12;
$result->bmi = round($kg / ($meter * $meter), 2);
$lb = round($kg / 0.45359237, 2);
if ($result->bmi < 18.5) {
$result->message = 'Underweight';
} elseif ($result->bmi <= 24.9) {
$result->message = 'Normal weight';
} elseif ($result->bmi <= 29.9) {
$result->message = 'Overweight';
} else {
$result->message = 'Obesity';
}
$result->metric = array(
'height' => "$cm centimeter",
'weight' => "$weight kilograms"
);
$result->imperial = array(
'height' => "$feet feet $inches inches",
'weight' => "$lb pounds"
);
return $result;
}
}