PHP global variables not working inside a function

php

Solution

Looks like homework, still:

<?php

$bool = 1;

boo();

function boo() {
global $bool;

if ($bool == 1) {
$bool = 2;
echo 'Hello World';

}


}
?> 

Or

<?php

$bool = 1;

boo(&$bool);

function boo(&$bool) {

if ($bool == 1) {
$bool = 2;
echo 'Hello World';

}


}
?> 

Problem

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?

Original source

Related problems