Dysfunctional Functions
Date: 05/05/06
(PHP Community) Keywords: php
Okay... I need some help with functions here. I've read the documentation on php.net, and just when I think I understand functions, I get thrown a curve ball. Here's the situation.
Lets say I have the following function:
function DoStuff($var1){
if($var1 == "z"){
$x = 1
return $x
}else{
$x = 2
return $x;
}
}
Now, lets say I call this function:
$passedVar = "z";
DoStuff($passedVar);
echo $x;
In theory, I should get an echo of "1" ($x)
But, I do not. $x seems null. Now, as far I know, the variable of $x should be getting passed back to the file that called the function. Am I wrong in my thinking?
Source: http://community.livejournal.com/php/447773.html