|  | Posted by James Pittman on 06/12/01 11:13 
Marco J.L. wrote:
 > Hello,
 >
 > how can I transfer a variable from a function to the part after the
 > function?
 >
 > thnx,
 >
 > Marco J.L.
 >
 >
 > <?php
 >
 > $var="before function";
 > func_xxxxx();
 > echo $var;
 >
 > Function func_xxxxx() {
 >  $var = "after function";
 > }
 > ?>
 >
 >
 >
 
 I believe you can do this if you pass the variable by reference:
 
 $var = "before function";
 myFunc($var);
 echo $var;
 
 function myFunc(\$foo)  {
 $foo = str_replace("before", "after", $foo);
 }
 
 
 But a more elegant way is to return the variable back to the program:
 
 $var = "before function";
 $var = myFunc($var);
 echo $var;
 
 function myFunc($foo)  {
 // Do some manipulation on $foo and set it to $bar
 $bar = str_replace("before", "after", $foo);
 return $bar;
 }
  Navigation: [Reply to this message] |