php - Function doesn't return value -
for reason function won't return value ciao
:
$a = "ciao"; function a() { return $a; }
i have no idea why.
functions can return variables have in local space, called scope:
$a = "ciao"; function a() { $a = 'hello`; return $a; }
will return hello
, because within a()
, $a
variable of it's own. if need variable within function, pass parameter:
$a = "ciao"; function a($a) { return $a; } echo a($a); # "ciao"
btw, if enable notices reported (error_reporting(-1);
), php have given notice return $a
in original code using undefined variable.
Comments
Post a Comment