I have the following code:
$SpeedA = 5;
$SpeedB = 5;
$Distance = 20;
function CalDistance ($SpeedA, $SpeedB,
$Distance)
{
$DistanceA = (($SpeedA / $SpeedB) *
$Distance) / (1 + ($SpeedA / $SpeedB));
Return $DistanceA;
}
echo $DistanceA;
I get this error:
Notice: undefined variable $DistanceA
Why $DistanceA
is regarded as undefined and how to fix it?
You never call the function
CalDistance
, before yourecho
. So, you try toecho
an undefined$DistanceA
.So, you could do something like this: