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

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

    Why don't you just build a simple function and TELL it?

    /**
     * Prints out $obj for debug
     *
     * @param any_type $obj
     * @param (string) $title
     */
    function print_all( $obj, $title = false )
    {
        print "\n
    \n"; if( $title ) print "
    $title
    \n"; print "
    \n\n";
        var_export( $obj );
        print "\n\n
    \n
    \n"; } print_all( $aUser, '$aUser' );

提交回复
热议问题