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? Link to comment https://forums.phpfreaks.com/topic/110255-using-same-variable-names/ 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. Link to comment https://forums.phpfreaks.com/topic/110255-using-same-variable-names/#findComment-565732 Share on other sites More sharing options...
MasterACE14 Posted June 15, 2008 Share Posted June 15, 2008 google variable scope Link to comment https://forums.phpfreaks.com/topic/110255-using-same-variable-names/#findComment-565840 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.