Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Read about <code>$GLOBALS</code> variable <a href="http://php.net/manual/en/reserved.variables.globals.php" rel="nofollow">in the documentation</a>.</p> <p>This is probably what you need. Depending on the way you determine which variable you need, you can for example user <code>array_search()</code> to find the proper name based on the value.</p> <p>Caution: <code>$GLOBALS</code> is about global scope's variables.</p> <p><strong>EDIT:</strong></p> <p>But this would be still a guess. You may try the following method to determine the name of the passed variable with ~100% certainty:</p> <ol> <li>Pass variable to the method with reference.</li> <li>Use <code>array_search()</code> for finding the name of the variable. If only one key matches it, you have your name. If not, go to the next step.</li> <li>Save the initial value of the variable and save the list of positions at which you have found matching elements.</li> <li>Change the variable's value into new one. Perform another search based on new value and get positions that are also in the list of positions from point no. 3.</li> <li>At this point you have probably found the name of the variable you are looking for.</li> </ol> <p>But...</p> <p>Is it really needed? I suggest that you should look for simpler solution, some better encapsulation of your code.</p> <p>Ps. <code>array_search()</code> actually returns no more than one key (<a href="http://php.net/manual/en/function.array-search.php" rel="nofollow">see documentation</a>). You should know that and make searching for multiple results a little more sophisticated to not skip the correct one if more than one variable matches your search criteria. (<strong>EDIT2:</strong> As mario suggested, <code>array_intersect($GLOBALS, array($var))</code> will suffice)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload