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

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

    I have this:

      debug_echo(array('$query'=>$query, '$nrUsers'=>$nrUsers, '$hdr'=>$hdr));
    

    I would prefer this:

      debug_echo($query, $nrUsers, $hdr);
    

    The existing function displays a yellow box with a red outline and shows each variable by name and value. The array solution works but is a little convoluted to type when it is needed.

    That's my use case and yes, it does have to do with debugging. I agree with those who question its use otherwise.

提交回复
热议问题