using variables from a file included

Hello

the code is like this :

variables.php:

<? $x = 1; ?>

functions.php:

<? require_once("variables.php"); function x () { echo "x = $x
"; } ?>

index.php:

<? require_once ("functions.php"); x() ?>

ERROR :
PHP Notice: Undefined variable: x in functions.php

this is not happening in languages like perl or c++ ; am i doing something wrong ?

OK problem solved global $var :)))))))) ;D

Hell NO!!!

You pass the variable in to the function!
[php]
$x = 1;
function x ( $param ) {
echo “x = $param
”;
}

x($x)
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service