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

前端 未结 24 1761
南旧
南旧 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:01

    I was looking for this but just decided to pass the name in, I usually have the name in the clipboard anyway.

    function VarTest($my_var,$my_var_name){
        echo '$'.$my_var_name.': '.$my_var.'
    '; } $fruit='apple'; VarTest($fruit,'fruit');

提交回复
热议问题