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

前端 未结 24 1919
南旧
南旧 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条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 02:05

    why we have to use globals to get variable name... we can use simply like below.

        $variableName = "ajaxmint";
    
        echo getVarName('$variableName');
    
        function getVarName($name) {
            return str_replace('$','',$name);
        }
    

提交回复
热议问题