Posted by cliff smith on 01/08/06 07:27
windandwaves wrote:
> Hi Folk
>
> Consider this:
>
> ---foo1.php
> $myvar = 10;
>
> --- foo2.php
> require_once("foo1.php");
>
> function funky {
> echo $myvar;
> }
>
> from my experience, funky does not print 10. How do I make $myvar "global"
> (not sure if this is the right word) so that it shows everywhere.
>
>
Variables outside a function are not directly available inside a
function. This is by design.
Ways to make the function "funky" work.
function funky() {
echo $GLOBALS['myvar'];
}
funky();
OR better, pass the variable to funky -
function funky( $func_var ) {
echo $func_var;
}
funky($myvar);
Hope this helps,
Cliff.
Navigation:
[Reply to this message]
|