PHP class to calculate a persons "Basal Metabolic Rate". Supports both imperial and metric measurements.
include_once "BMR.php";
$options = [
'height'=>'5,7',
'weight_lbs'=>160,
'age'=>28,
'gender'=>'m'
];
$BMR = new BMR($options);
echo $BMR->GetBMR();
For CM (Centimeters) pass the value "height"->150
For feet & inches separate by comma "height"=>"5,7"
or "height"=>"6,3"
KG (Kilograms): use key "weight" and pass the value "weight"->80
LBS (pounds): use key "weight_lbs" and pass the value "weight_lbs"->176
accepted values (case-insensitive): m
male
f
female
pass the value "age"=>28
you may set the values using the following
$BMR->SetHeight(170);
or $BMR->SetHeight('5,7');
$BMR->SetWeight(80);
or $BMR->SetWeight(160,'lbs');
$BMR->SetGender('male');
or $BMR->SetGender('female');
$BMR->SetAge(28);
$BMR = new BMR;
$BMR->SetHeight(170);
$BMR->SetWeight(80);
$BMR->SetGender('male');
$BMR->SetAge(28);
echo $BMR->GetBMR();
you may use $BMR->CalculateBMR()
to perform the calculation, which will return true
or false
.
if this returns false
you may locate the error mesage with echo $BMR->ErrorMsg
every function except GetBMR() will store an error message if false
if (!$BMR->SetHeight('some incorrect value')){
echo $BMR->ErrorMsg; // returns: Invalid height - out of range
}
if (!$BMR->CalculateBMR()){
echo $BMR->ErrorMsg;
}