Jump to content

Using Same Variable Names?


TJMAudio
 Share

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.