Notice: Undefined variable: e from function

I am a newby having trouble getting an array back from a function. I get an error "Notice: Undefined variable: e in C:\Program Files\Apache Software

[php]

$m = 0.111;
$A = 299792458;
$Z = 2;

energyFunction($m,$A,$Z);

print_r($e);

function energyFunction($m,$A,$Z) {
$xjoule = $m * ($A * $Z) * ($A * $Z);
$xamp = $A * $Z;
$xohm = $m / $Z;
$xfarad = ($Z * $Z) / $m;
$xtesla = $m / ($A * (($Z * $Z) * $Z));
$xelectricField= $m / ($Z * $Z);
$xacceleration = $A;
$xwatt = $m * ($A * $A) * $Z;
$xvolt = $m * $A;
$xcoulomb = $A * ($Z * $Z);
$xweber = $m * ($Z * $Z);
$xseimen = $Z / $m;
$xhenry = $m;
$xtime = $Z;

$e = array(“xtime”=>$xtime,“xhenry”=>$xhenry);
print_r($e);
return $e;
}[/php]

print_r($e); on line line contains e with clearly you have not set yet.

You have to put $e = infront of energyFunction($m,$A,$Z);

so

[php]$e = energyFunction($m,$A,$Z);[/php]

or simply remove that print_r

Just to make it more clear. The $e in the fuction is of an other scope as the one outside. So the value that your return in an function has to be assigned to a variable outside of that funtion.

and it line 9, where I typed line line.

Sponsor our Newsletter | Privacy Policy | Terms of Service