混合面板对象 php
两部分问题:调用 Mixpanel api 后,我返回类似这样的内容
stdClass Object (
[legend_size] => 1
[data] => stdClass Object (
[series] => Array (
[0] => 2011-04-06
[1] => 2011-04-07 )
[values] => stdClass Object (
[Login loaded] => stdClass Object (
[2011-04-06] => 1
[2011-04-07] => 1
)
)
)
)
假设我将其存储在 $data 中,
如果这样做,
$value = $data->data->values->Login loaded
我会收到错误,因为登录和加载之间存在空格。我该如何逃离这个空间?
第二个问题
一旦我弄清楚了上述问题,我可以做类似
$value = $data->data->values->Login->$date
where 的
$date = '2011-05-06'
事情吗?我可以用变量代替类名吗?
谢谢。
Two part question: After calling the Mixpanel api I am returned something like this
stdClass Object (
[legend_size] => 1
[data] => stdClass Object (
[series] => Array (
[0] => 2011-04-06
[1] => 2011-04-07 )
[values] => stdClass Object (
[Login loaded] => stdClass Object (
[2011-04-06] => 1
[2011-04-07] => 1
)
)
)
)
Let's say I stored this in $data
If I do
$value = $data->data->values->Login loaded
I get an error because of the space in between Login and loaded. How do I escape this space?
Second question
Once I get the above figured out, can I do something like
$value = $data->data->values->Login->$date
where
$date = '2011-05-06'
? Can I stick in a variable in place of a class name?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个问题:
$value = $data->data->values->{'登录已加载'}
或:第二个问题:是的
您几乎可以使用任何内容作为变量名称(包括对象成员)(如果您使用变量变量、
{}
变量包装器等)。例如:
编辑:当我们这样做时,this永远不会有效:
您无法访问存储在变量中的类实例的静态属性。但是,您可以执行以下操作:
First Question:
$value = $data->data->values->{'Login loaded'}
or:Second Question: Yes
You can pretty much use anything as a variable name (including object members) if you use variable variables,
{}
variable wrappers, and the like.E.g.:
EDIT: While we're at it, this is never valid:
You can't access the static properties of a class instance stored in a variable. However, you could do something like: