混合面板对象 php

发布于 2024-10-31 05:55:20 字数 838 浏览 0 评论 0原文

两部分问题:调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北凤男飞 2024-11-07 05:55:20

第一个问题:$value = $data->data->values->{'登录已加载'} 或:

$key = 'Login loaded';
$value = $data->data->values->$key

第二个问题:是的

您几乎可以使用任何内容作为变量名称(包括对象成员)(如果您使用变量变量、{} 变量包装器等)。

例如:

$this->$foo
${'a weird variable name'}
$object->$something->{'very weird'}
$foo = 'bar';  $foo = 3; // $bar = 3 now.

编辑:当我们这样做时,this永远不会有效:

$foo = new Foo;
$foo::bar(); // syntax error

您无法访问存储在变量中的类实例的静态属性。但是,您可以执行以下操作:

$foo = new Foo;
call_user_func(get_class($foo) . '::bar');

First Question: $value = $data->data->values->{'Login loaded'} or:

$key = 'Login loaded';
$value = $data->data->values->$key

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.:

$this->$foo
${'a weird variable name'}
$object->$something->{'very weird'}
$foo = 'bar';  $foo = 3; // $bar = 3 now.

EDIT: While we're at it, this is never valid:

$foo = new Foo;
$foo::bar(); // syntax error

You can't access the static properties of a class instance stored in a variable. However, you could do something like:

$foo = new Foo;
call_user_func(get_class($foo) . '::bar');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文