Last active
August 29, 2015 14:02
-
-
Save nicklasos/d197444cb088fdd7a15c to your computer and use it in GitHub Desktop.
Variable name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function variable_name(&$var) | |
{ | |
$old = $var; | |
$var = $new = 'UNIQUE' . mt_rand() . 'VARIABLE'; | |
$vname = false; | |
foreach($GLOBALS as $key => $val) { | |
if($val === $new) { | |
$vname = $key; | |
} | |
} | |
$var = $old; | |
return $vname; | |
} | |
$a = 'asdf'; | |
$b = 'asdf'; | |
$c = false; | |
$d = true; | |
$FooBar = 'test'; | |
echo variable_name($a); // a | |
echo variable_name($b); // b | |
echo variable_name($c); // c | |
echo variable_name($d); // d | |
echo variable_name($FooBar); // FooBar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ебануться