属性名称包含-(连字符)时如何访问对象属性 [英] How to access object property when property name contains - (hyphen)
本文介绍了属性名称包含-(连字符)时如何访问对象属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要-
的转义序列或php的减号.该对象具有一个名称/值"对,其中名称恰巧在两个词之间具有-
.
I need an escape sequence for -
or the minus sign for php. The object has a name-value pair where the name happens to be having -
between 2 words.
我无法使用标准转义序列\
(始终未记录-
)执行此操作.
I can't do this using \
the standard escape sequence (-
isn't anyways documented).
我可以将名称存储在可以使用的$myvariable
中,但是出于好奇,可以执行以下操作吗?
I can store the name in a $myvariable
which can be used but out of curiosity is it possible to do the following?
$myobject->myweird-name
由于-
推荐答案
这是您需要的:
$myobject->{'myweird-name'};
这篇关于属性名称包含-(连字符)时如何访问对象属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文