用PHP读取对象/数组

时间:2016-04-18 06:52:11

标签: php arrays

我正在开发Facebook领导API并成功获得我的主管回复

use FacebookAds\Object\Lead;

    $form = new Lead('LEAD_ID');
    $re = $form->read();
    echo '<pre>';
    print_r($re);

并且响应采用以下格式:

FacebookAds\Object\Lead Object
(
    [changedFields:protected] => Array
        (
        )

    [api:protected] => FacebookAds\Api Object
        (
            [session:FacebookAds\Api:private] => FacebookAds\Session Object
                (
                    [appId:protected] => 448283968712152
                    [appSecret:protected] => 0cf8998603f3050f9d80ded4cecdb7f7
                    [accessToken:protected] => EAAGXtj62rdgBAP0ZCjmnddu3ZBIgZAECUluzPL6CGUuZB07tPUlERk4L1iRb2gy31qlUx2ExBENZBegpvfHxmxsJYks8rghrKOZBHMWEblEgsIvo5GF3ySzbyVszg7lbYIuBSgeFdzAMq6GuW6iZCQrgXd4KfAVoiQZD
                    [appSecretProof:protected] => c6112ce522414623dea1fb41cc29f6f15ca480845b8490d7c45ec67a485fa3f6
                )

            [logger:protected] => FacebookAds\Logger\NullLogger Object
                (
                )

            [httpClient:protected] => FacebookAds\Http\Client Object
                (
                    [requestPrototype:protected] => FacebookAds\Http\Request Object
                        (
                            [client:protected] => FacebookAds\Http\Client Object
 *RECURSION*
                            [headers:protected] => 
                            [method:protected] => GET
                            [protocol:protected] => https://
                            [domain:protected] => 
                            [path:protected] => 
                            [graphVersion:protected] => 
                            [queryParams:protected] => 
                            [bodyParams:protected] => 
                            [fileParams:protected] => 
                        )

                    [responsePrototype:protected] => FacebookAds\Http\Response Object
                        (
                            [request:protected] => 
                            [statusCode:protected] => 
                            [headers:protected] => 
                            [body:protected] => 
                            [content:protected] => 
                        )

                    [defaultRequestHeaders:protected] => FacebookAds\Http\Headers Object
                        (
                            [storage:ArrayObject:private] => Array
                                (
                                    [User-Agent] => fb-php-ads-2.5.1
                                    [Accept-Encoding] => *
                                )

                        )

                    [adapter:protected] => FacebookAds\Http\Adapter\CurlAdapter Object
                        (
                            [curl:protected] => FacebookAds\Http\Adapter\Curl\Curl Object
                                (
                                    [handle:protected] => Resource id #34
                                )

                            [opts:protected] => ArrayObject Object
                                (
                                    [storage:ArrayObject:private] => Array
                                        (
                                            [78] => 10
                                            [13] => 60
                                            [19913] => 1
                                            [42] => 1
                                            [10065] => /home/leadsgeneration/public_html/v1/vendor/facebook/php-ads-sdk/src/FacebookAds/Http/../../../fb_ca_chain_bundle.crt
                                        )

                                )

                            [client:protected] => FacebookAds\Http\Client Object
 *RECURSION*
                        )

                    [caBundlePath:protected] => /home/leadsgeneration/public_html/v1/vendor/facebook/php-ads-sdk/src/FacebookAds/Http/../../../fb_ca_chain_bundle.crt
                    [defaultGraphBaseDomain:protected] => facebook.com
                )

            [defaultGraphVersion:protected] => 2.5
        )

    [parentId:protected] => 
    [data:protected] => Array
        (
            [ad_id] => 
            [adset_id] => 
            [campaign_id] => 
            [created_time] => 2016-04-18T04:17:55+0000
            [field_data] => Array
                (
                    [0] => Array
                        (
                            [name] => email
                            [values] => Array
                                (
                                    [0] => varunroute69@gmail.com
                                )

                        )

                    [1] => Array
                        (
                            [name] => phone_number
                            [values] => Array
                                (
                                    [0] => +919731688688
                                )

                        )

                    [2] => Array
                        (
                            [name] => full_name
                            [values] => Array
                                (
                                    [0] => Varun Majety
                                )

                        )

                )

            [form_id] => 
            [id] => 571052196402628
            [post] => 
        )

)

我想将[data:protected][field_data]存储在数据库中,所以我想读取这个数组但是当我尝试像echo '-->'.$re['FacebookAds\Object\Lead Object']['data:protected'][field_data][0]['name'];那样回应时,它会抛出一个错误。

如何阅读以上格式?非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

$form = new \FacebookAds\Object\Lead('LEAD_ID');
$form->read();
echo '<pre>';
print_r($form->getData());

会给你

Array
(
[ad_id] => 
[ad_name] => 
[adset_id] => 
[adset_name] => 
[campaign_id] => 
[campaign_name] => 
[created_time] => 2016-09-18T06:57:13+0000
[custom_disclaimer_responses] => 
[field_data] => Array
    (
        [0] => Array
            (
                [name] => full_name
                [values] => Array
                    (
                        [0] => 
                    )

            )

        [1] => Array
            (
                [name] => email
                [values] => Array
                    (
                        [0] => test@fb.com
                    )

            )

        [2] => Array
            (
                [name] => phone_number
                [values] => Array
                    (
                        [0] => 
                    )

            )

    )

[form_id] => 
[id] => 1681384948848301
[is_organic] => 
[post] => 
)