This is how scope works in PHP: the variables named $result
are all different instances, since they belong to the scopes of the functions in which they occur.
This is a good thing, and promotes good design.
You should return
the value of your interest from fna
and fnb
instead of trying to use so-called side-effects. And then pass that value to your final function, so that it is clear it needs it. All this will make your code much more readable:
$result = isset($_GET['str']) ? fna() : fnb(); // <--- get return value
function fna(){
return 5; // <--- return it
}
function fnb(){
return 9;
}
function fnc($result){ // <--- what the function needs
if ($result == 5){
}
}
fnc($result); // <--- pass the value that the function needs.