Why is this function returning me "disapproved"?
$nFis = 90
function resFis(){
if($nFis >= 60){
return "aprovado";
}
else{
return "reprovado";
}
}
Why is this function returning me "disapproved"?
$nFis = 90
function resFis(){
if($nFis >= 60){
return "aprovado";
}
else{
return "reprovado";
}
}
Because $nFis
is not defined in the resFis
function.
It is probably a global variable, so you should change your method to:
function resFis(){
global $nFis;
if($nFis >= 60){
return "aprovado";
}
else{
return "reprovado";
}
}
Or pass it by parameter:
function resFis($nFis){
if($nFis >= 60){
return "aprovado";
}
else{
return "reprovado";
}
}
The error happens because the function is testing an empty variable. To solve, do the following.
At the place where you called the resFis () function, do:
resFiz($nFis);
And in your role do
function resFis($nFis){
if($nFis >= 60){
return "aprovado";
}
else{
return "reprovado";
}
}