Page 1 of 1

setting vars in function

Posted: Tue Aug 17, 2004 11:42 am
by John Cartwright
functions.php

Code: Select all

<?php
		function svar($var,$condition)
		{
			$vars["{$var}"] = $condition;
			return $vars[$var];
		}
?>
and on another file which inludes functions.php

Code: Select all

<?php
		$varcontrol->svar("article_header",$row["title"]);
?>
but I'm having sort of a brain bubble.
I know the function will delete all the vars it creates at the end of a function but how do I get this var to remain set, so it acts like it was set by $vars["varname"]

Posted: Tue Aug 17, 2004 12:35 pm
by hawleyjr
Can't you just do it like this?

Code: Select all

<?php
      function svar($var,$condition) 
      { 
         $vars["$var"] = $condition; 
         return $vars[$var]; 
      } 
?>

Posted: Tue Aug 17, 2004 12:53 pm
by John Cartwright
oops I did have the extra {} but that wouldn't solve anything.

$var[$varname] will never be set outside the function