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

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

    From php.net

    @Alexandre - short solution

    
    

    @Lucas - usage

    my_object_property = "My object property  string.";
        }
      }
      $obj = new myclass;
      echo vname($obj->my_object_property, $obj); // Outputs: my_object_property
    ?>
    

提交回复
热议问题