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

Member Avatar for rajarajan2017

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?

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.

Member Avatar for rajarajan2017

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.

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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.