Jump to content

Using Same Variable Names?


TJMAudio

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.