View Single Post
  #3 (permalink)  
Old 10-30-2007, 11:08 AM
wige's Avatar
wige wige is online now
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,655
wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9
Default Re: Using Variables outside a function

Assuming you are coding in PHP: If $new_var is assigned before the function begins, you can tell the function to use the the "global" version of $new_var rather than creating a local copy using the global operator.

PHP Code:
function example ($input_var) {
   global 
$new_var;
   if (
$input_var == option1) {
      
$new_var new_desired_output1;
   }
   else {
      
$new_var new_desired_output2;
   }

This may be preferable to pass by reference as you do not need to add the parameter to existing functions, and it is simpler to implement when you are dealing with multiple global variables, although both methods should have similar overhead.
__________________
The best way to learn anything, is to question everything.
Reply With Quote