如何在php中读取此对象以检索电子邮件

时间:2015-09-30 08:39:36

标签: php object

这只是一个循环,但我想要检索所有的电子邮件。

Guzzle\Service\Resource\Model Object
(
    [structure:protected] => 
    [data:protected] => Array
        (
            [type] => user.list
            [pages] => Array
                (
                    [type] => pages
                    [next] => https://xxxx.com/users?per_page=50&page=2
                    [page] => 1
                    [per_page] => 50
                    [total_pages] => 234
                )

            [users] => Array
                (
                    [0] => Array
                        (
                            [type] => user
                            [id] => 560b99861cf5c8112a00012e
                            [user_id] => 
                            [anonymous] => 
                            [email] => abcd@gmail.com
                            [name] => Shivaji 
                            [pseudonym] => 
                            [avatar] => Array
                                (
                                    [type] => avatar
                                    [image_url] => 
                                )

                            [app_id] => xhxxxxf
                            [companies] => Array
                                (
                                    [type] => company.list
                                    [companies] => Array
                                        (
                                        )

                                )

                            [location_data] => Array
                                (
                                    [type] => location_data
                                    [city_name] => 
                                    [continent_code] => AS
                                    [country_name] => India
                                    [latitude] => 28.4667
                                    [longitude] => 77.0333
                                    [postal_code] => 
                                    [region_name] => Haryana
                                    [timezone] => Asia/Calcutta
                                    [country_code] => IND
                                )

                            [last_request_at] => 1443600774
                            [last_seen_ip] => 125.19.45.202
                            [created_at] => 1443600774
                            [remote_created_at] => 1443600686
                            [signed_up_at] => 1443600686
                            [updated_at] => 1443600774
                            [session_count] => 1
                            [social_profiles] => Array
                                (
                                    [type] => social_profile.list
                                    [social_profiles] => Array
                                        (
                                        )

                                )

                            [unsubscribed_from_emails] => 
                            [user_agent_data] => Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
                            [tags] => Array
                                (
                                    [type] => tag.list
                                    [tags] => Array
                                        (
                                        )

                                )

                            [segments] => Array
                                (
                                    [type] => segment.list
                                    [segments] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [type] => segment
                                                    [id] => 551d080b5e3a0fc0f4000043
                                                )

                                            [1] => Array
                                                (
                                                    [type] => segment
                                                    [id] => 551d080b5e3a0fc0f4000042
                                                )

                                        )

                                )

                            [custom_attributes] => Array
                                (
                                    [cust_id] => 
                                )

                        )
)

1 个答案:

答案 0 :(得分:0)

尝试

$users = $your_response_array["data"]["users"];
foreach ($users as $user) {
    var_dump($user["email"] );
}

如果它是你正在处理的对象,你需要使用:

$users = $your_response_obj->data["users"];

但是当你的转储声明"数据"数组受到保护,因此需要阅读guzzle文档以找出哪种方法可以访问数据属性。