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

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

    I really fail to see the use case... If you will type print_var_name($foobar) what's so hard (and different) about typing print("foobar") instead?

    Because even if you were to use this in a function, you'd get the local name of the variable...

    In any case, here's the reflection manual in case there's something you need in there.

提交回复
热议问题