IMC = weight in kg divided by height times height, which is the response of Caymmi.
But there are other operations that return the same result:
1 - using pow(x,y)
function returns x high to the power of y, in the case of $squared height. See example in ideone
$peso = $_POST['peso'];
$altura = $_POST['altura'];
function imc($altura, $peso){
$altura = str_replace(',', '.', $altura);
$result = $peso/pow($altura, 2);
return $result;
}
echo"seu imc é: " .imc($altura , $peso);
2 - Inverse of a division. See example on ideone
could use too $result = 1/(pow($altura, 2)/ $peso);
that would return the same result.
pow($altura, 2) $peso
1 ÷ _______________ = 1 x ________________ = $peso/pow($altura, 2)
$peso pow($altura, 2)
3 - From PHP 5.6 you may prefer to use the operator **
See example on ideone
$peso = $_POST['peso'];
$altura = $_POST['altura'];
function imc($altura, $peso){
$altura = str_replace(',', '.', $altura);
$result = $peso/$altura**2;
return $result;
}
echo"seu imc é: " .imc($altura , $peso);
the result can be formatted using the function number_format()
BMI is not = weight in kg / (height in metres * height in metres)
– user60252