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

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -