0

OK gang! I have another stumper!

I want to add a variable to an array from within a function and I will not know the variables original name so how can I find this?

For instance:

function AddVariable($vartoadd)
{
  $varlist[] = $vartoadd;
}

$domain = http://www.dodatingsiteswork.com;
AddVariable($domain);

Once I get into the function AddVariable(), I will not know that $domain is the name of the variable to add. How can I find the true name of the variable so that I can add that name to my array?

Thanks,

Pete

4
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by jj_pix
0

I didn't get you, because according to the function concept, it will pass the data to the called function and you cannot find the variable name. you just transferring the data to another thats it. What do you want to do? if you want variable (what is the purpose? Question is not clear?

0

Thats the whole problem, you are just transferring the data, actually, just a copy of the data not even the real data.

The idea is to be able to store the real variables name in an array so that something else (another function) can reference the real variable at a later time.

0

If you want to show while debugging it will show the variable automatically (some softwares) or else you have to use some specific syntax to achieve those. But still I am not come across the thing, that variable stored in a variable with the name. Still it is a very different question. I understoodd that you are trying to show in the watchlist, but this is not the way? If anybody come with a solution then its new to me and I have learned one more thing from that solution. Hope I too expect.

0

Had same problem, but found a solution.

$varlist=array();

function AddVariable($vartoadd)
{
    //sets your array as global (gets and writes)
      global $varlist; 

  $varlist[] = $vartoadd;
}
$domain = http://www.dodatingsiteswork.com;
AddVariable($domain);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.