Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't acces variables 1

Status
Not open for further replies.

801119

Programmer
Joined
Apr 10, 2000
Messages
311
Location
SE
Why can't I access any variables from out side of functions??
This code for example will not print anything,.. why?? :s
<?
$txt = &quot;hello world&quot;;
function xPrint()
{
echo $txt;
}
xPrint();
?>

My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
Functions have a different variable scope from the main body of the script. The reference to $txt you use inside the function is a different variable from the one you reference outside the function. They just happen to have the same name.

This page is from the PHP online manual on variable scoping:
Want the best answers? Ask the best questions: TANSTAAFL!
 
thanks for the quick respond, now I can save some of my hair!! *rolf* ;D

My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top