Skip to content

Instantly share code, notes, and snippets.

@nicklasos
Last active August 29, 2015 14:02
Show Gist options
  • Save nicklasos/d197444cb088fdd7a15c to your computer and use it in GitHub Desktop.
Save nicklasos/d197444cb088fdd7a15c to your computer and use it in GitHub Desktop.
Variable name
<?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
@nicklasos
Copy link
Author

Ебануться

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment