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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A couple of Questions!! Pls

Status
Not open for further replies.

Forri

Programmer
Joined
Oct 29, 2003
Messages
479
Location
MT
Hi

I would like to ask:

1) if i have the following:

Code:
 <?PHP
 
 $Counter = 0;
  
 UPDATEVARIABLE();
  
 echo $Counter;

 [b]function [/b]UPDATEVARIABLE()
 {
   $Counter = 5;
 }
?>

Will the above print out 5 or 0; Does the function update the Variable or update it only within the function?

Ok. for now thats it...then i'll make another question according to the above answer!

Thanks
Nick
 
Sorry forgot piece of syntax which is the:

global $counter;

before

$counter = 5;

Still awaiting your reply!

Thanks again
 
Your function will update the global variable $Counter when you include the global statement from your second post.

The scope of variables in PHP is local to a function. Using the global $myVar statement will use the variable from outside the function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top