Click to See Complete Forum and Search --> : Variable Scope


Marlon_Br
08-04-2006, 09:39 AM
Hi, I want to use a variable that was created in one function in another function,,, how can I do that?

I´ve tried :

<?php
$a = NULL;

function test1()
{
global $a;
$a = "Anything";
}

function test2(){
echo $a;
}

test1();
test2();

?>

and it doens´t work...

sitehatchery
08-04-2006, 10:18 AM
function test2($a);

Marlon_Br
08-04-2006, 11:01 AM
Something like this:

<?php

function test1()
{
global $a;
$a = "Anything";
}


function test2($a){
echo $a;
}

test1();
test2($a);

?>

Ok,, but I´m trying to just be able to use the variable that was created in the first function, one the second function, without having to pass any argument.