Re: Is there a way to access all the variables in my script?

From: Date: Fri, 21 Mar 2003 10:36:42 +0000
Subject: Re: Is there a way to access all the variables in my script?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-140572@lists.php.net to get a copy of this message
$GLOBALS Daevid Vincent wrote:
Is there some global array or something that contains all the variable names (not even values per se) that are used in my script. Here's the scenario. Like most of you, I do a lot of mySQL db work. So I tend to use this: if (mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result,MYSQL_ASSOC); while(list($myVariableName,$sqlFieldName)=each($row)) { $$myVariableName = $sqlFieldName; } } So now I have a bunch of variables all named say, $company_name, $company_id, $company_phone, etc... What I want to do is make a function that can step through all the $company_ variables and unset them all. (I imagine I'll just string compare to "company_" and then prefix the result with $$, then set = "", etc. you get the idea) I suppose I could re-write all my code and use the $row['company_id'] method instead then clear $row[] but it would be nice to know if there is a way to do this 'my way' as well...


« previous php.general (#140572) next »