TJMAudio Posted June 15, 2008 Share Posted June 15, 2008 Is it possible to use the same variable names in the same script more than once, say whether it be inside a function or in the script itself, without overwriting data? First example: $query = mysql_query("SELECT * FROM table1"); while($row = mysql_fetch_array($query)) { $variable1 = $row['info']; } $query = mysql_query("SELECT * FROM table2"); while($row = mysql_fetch_array($query)) { $variable2 = $row['info']; } Would $variable1 and $variable2 contain their own data, or would $variable1 be rewrote when $query and $row are reused? Next example is reusing variables in multiple functions... function one($var) { $info = $var; } function two($var) { $info = $var; } Is that possible, or will function two overwrite function one, and vice versa? Quote Link to comment Share on other sites More sharing options...
marklarah Posted June 15, 2008 Share Posted June 15, 2008 no, they should be okay, as they will only be used when the script actually needs it. As long as you transfer the info into a separate variable (depends how you are using it), but you should have $info1 and $info2, or just return the outcome of the function. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 15, 2008 Share Posted June 15, 2008 google variable scope Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.