Is there a way to access all the variables in my script?
| From: | Daevid Vincent | Date: | Thu, 20 Mar 2003 20:38:12 +0000 |
| Subject: | Is there a way to access all the variables in my script? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-140475@lists.php.net to get a copy of this message | ||
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...