By what you see on the internet 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 raised to the power of y, in the case $ height squared. See example on 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 also use $result = 1/(pow($altura, 2)/ $peso);
which 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 in 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 ()