且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从对象的其中一个属性具有$符号的对象获取php变量

更新时间:2023-11-29 23:42:46

将其封装为单引号字符串:

Encapsulate it as a single-quoted string:

echo $object->id->{'$t'};

请注意,出于与不能使用$object->id->$t相同的原因,不能使用双引号:PHP将尝试对$t进行插值.但是,如果您逃脱了美元符号,则可以使用双引号:

Note that you cannot use double quotes for the same reason you cannot use $object->id->$t: PHP will attempt to interpolate $t. However, you could use double quotes if you escape the dollar sign:

echo $obj->id->{"\$t"};

您可以在这个简单的演示中看到它的运行情况.

You can see it working in this simple demo.