How to get a variable name as a string in PHP?

前端 未结 24 1769
南旧
南旧 2020-11-22 01:35

Say i have this PHP code:

$FooBar = \"a string\";

i then need a function like this:

print_var_name($FooBar);
24条回答
  •  Happy的楠姐
    2020-11-22 02:11

    Use this to detach user variables from global to check variable at the moment.

    function get_user_var_defined () 
    {
        return array_slice($GLOBALS,8,count($GLOBALS)-8);     
    }
    
    function get_var_name ($var) 
    {
        $vuser = get_user_var_defined(); 
        foreach($vuser as $key=>$value) 
        {
            if($var===$value) return $key ; 
        }
    }
    

提交回复
热议问题