Possible Duplicate:
php function variable scope
I am using below code to test with a global variable. It seems that a global variable cannot be compared inside a function.
Why is it not displaying 'hello world' in the output?
Below is the code that I am trying:
<?php
$bool = 1;
function boo() {
if ($bool == 1) {
$bool = 2;
echo 'Hello World';
}
}
?>
When I remove function boo(), 'hello world' is displayed. Why is it not displaying when function exists?
$boolis not defined in the function scope. You need to access it globally, or better, pass it to the function.$booldoesn't exists in the function scope.