0

这是我返回的对象的 print_r() :

    Array
(
    [0] => stdClass Object
        (
            [list_id] => 547009977
            [list_name] => Master List
            [list_type] => email
            [member_data] => Array
                (
                    [0] => stdClass Object
                        (
                            [name] => work_phone
                            [value] => 
                        )

                    [1] => stdClass Object
                        (
                            [name] => city
                            [value] => 
                        )

                    [2] => stdClass Object
                        (
                            [name] => restricted_since
                            [value] => 
                        )

                    [3] => stdClass Object
                        (
                            [name] => unsub_campaign_id
                            [value] => 
                        )

                    [4] => stdClass Object
                        (
                            [name] => title
                            [value] => 
                        )

                    [5] => stdClass Object
                        (
                            [name] => comments
                            [value] => 
                        )

                    [6] => stdClass Object
                        (
                            [name] => company_name
                            [value] => 
                        )

                    [7] => stdClass Object
                        (
                            [name] => Info
                            [value] => 
                        )

                    [8] => stdClass Object
                        (
                            [name] => address_hash
                            [value] => 
                        )

                    [9] => stdClass Object
                        (
                            [name] => hash
                            [value] => 2054ee9827
                        )

                    [10] => stdClass Object
                        (
                            [name] => country
                            [value] => 
                        )

                    [11] => stdClass Object
                        (
                            [name] => id
                            [value] => 45
                        )

                    [12] => stdClass Object
                        (
                            [name] => gender
                            [value] => 
                        )

                    [13] => stdClass Object
                        (
                            [name] => postalcode
                            [value] => 
                        )

                    [14] => stdClass Object
                        (
                            [name] => address_1
                            [value] => 
                        )

                    [15] => stdClass Object
                        (
                            [name] => create_date
                            [value] => 2013-07-15T15:31:35+00:00
                        )

                    [16] => stdClass Object
                        (
                            [name] => optin_status_last_updated
                            [value] => 2013-07-15T15:31:35+00:00
                        )

                    [17] => stdClass Object
                        (
                            [name] => Purchased
                            [value] => 
                        )

                    [18] => stdClass Object
                        (
                            [name] => marital_status
                            [value] => 
                        )

                    [19] => stdClass Object
                        (
                            [name] => optin_status
                            [value] => null
                        )

                    [20] => stdClass Object
                        (
                            [name] => last_updated
                            [value] => 2013-07-15T15:31:35+00:00
                        )

                    [21] => stdClass Object
                        (
                            [name] => address_2
                            [value] => 
                        )

                    [22] => stdClass Object
                        (
                            [name] => home_phone
                            [value] => 
                        )

                    [23] => stdClass Object
                        (
                            [name] => fax
                            [value] => 
                        )

                    [24] => stdClass Object
                        (
                            [name] => first_name
                            [value] => CoregTest
                        )

                    [25] => stdClass Object
                        (
                            [name] => bounce_campaign_id
                            [value] => 
                        )

                    [26] => stdClass Object
                        (
                            [name] => Page
                            [value] => 
                        )

                    [27] => stdClass Object
                        (
                            [name] => is_cass_certified
                            [value] => 0
                        )

                    [28] => stdClass Object
                        (
                            [name] => last_name
                            [value] => 
                        )

                    [29] => stdClass Object
                        (
                            [name] => restricted
                            [value] => 0
                        )

                    [30] => stdClass Object
                        (
                            [name] => mobile_phone
                            [value] => 
                        )

                    [31] => stdClass Object
                        (
                            [name] => email_address
                            [value] => coregtest@chrisjallen.com
                        )

                    [32] => stdClass Object
                        (
                            [name] => ip_address
                            [value] => 
                        )

                    [33] => stdClass Object
                        (
                            [name] => state
                            [value] => 
                        )

                )

        )

)

我要做的就是访问我的 php 代码中的 list_id 。如果我将它放入 $result 变量中:

 $result = $vr->searchListMembers( array(
        'session_id'  => $sid,
        'field_name'  => 'email_address',
        'field_value' => $email,
        'max_records' => 1
    ) );

我试过了

$result->list_id

$result[0]['list_id']

这似乎很明显,但我在这里遗漏了一些东西。

4

6 回答 6

2
$list_id = $result['list_id'];

但是,list_id不在您的代码中。所以也许你的意思是session_id。无论如何,语法是:

array['key']
于 2013-07-17T14:15:01.867 回答
2

尝试:

$list_id = $result[0]->list_id;
于 2013-07-17T14:27:48.393 回答
1

ChromePHP 似乎不是一个非常有用的工具。这是因为 PHP 和 JavaScript 具有不同的数据类型/数据结构,因此 JavaScript 控制台输出不会告诉您对象在 PHP 中的外观。

在 JavaScript 中,可以使用[]. 在 PHP 中,使用不同的语法访问对象和数组。PHP 数组使用[]和对象使用->.

如果你想调试 PHP,我建议你使用var_dump(或print_r),这将显示你是否有一个数组或一个对象。JavaScript 控制台将始终显示对象,并且不是很有用。

在您的情况下,您需要通过以下方式访问您的元素:

$result[0]->list_id
于 2013-07-17T14:30:26.010 回答
0

忽略 list_I'd 不存在的事实实际上取决于您使用的 searchListMember 方法的返回类型。如果返回的 var 是一个对象,你必须使用 ->list_id 如果它是一个数组,那么它确实与结构有关,但它应该像 $result['list_id']

于 2013-07-17T14:25:08.360 回答
0

尝试这个!

print $result[0]->list_id;
于 2013-07-17T14:30:50.500 回答
0

如果你这样做:

$result = $vr->searchListMembers( array(
        'session_id'  => $sid,
        'field_name'  => 'email_address',
        'field_value' => $email,
        'max_records' => 1
    ) );

$result 是一个数组。

所以首先你必须访问第一个元素:$result[0]

然后,它是一个 stdClass 对象,因此您可以使用运算符访问其属性->

$result[0]->list_id
于 2013-07-17T14:34:33.667 回答