Making global var from inside a function in PHP

boydseahorse

New Member
I am trying to define dynamically variables. I am using a function for this, but I don't know how to define the new var as global (because it never created before the function).is that possible ?Thanks.editok, this is what I've built. is it that dangerous ?\[code\]function extract_values($row) { foreach ($row as $key => $value){ global $$key; $$key = $value; }}\[/code\]and then I'm trying to make my life easier like that:\[code\]$result = mysql_query("SELECT first_name, last_name, address FROM users ORDER BY id ASC"); while ($row = mysql_fetch_array($result)){ extract_values($row);#[do some stuff with the variables.]#}\[/code\]I am doing it to save time. instead of creating for each column it's own variable like\[code\]$first_name = $row['first_name'];\[/code\]This function does that for me.I don't see why in this case it might be dangerous..or as usuall, i am missing something..
 
Back
Top