Question

I have the following result from authenticating a Facebook profile:

Array
(
    [provider] => Facebook
    [uid] => value
    [info] => Array
        (
            [name] => value
            [image] => value
            [nickname] => value
            [first_name] => value
            [last_name] => value
            [location] => value
            [urls] => Array
                (
                    [facebook] => value
                )

        )

    [credentials] => Array
        (
            [token] => SECRET
            [expires] => value
        )

    [raw] => Array
        (
            [id] => value
            [name] => value
            [first_name] => value
            [last_name] => value
            [link] => value
            [username] => value
            [location] => Array
                (
                    [id] => value
                    [name] => value
                )

            [education] => Array
                (
                    [0] => Array
                        (
                            [school] => Array
                                (
                                    [id] => value
                                    [name] => value
                                )

                            [concentration] => Array
                                (
                                    [0] => Array
                                        (
                                            [id] => value
                                            [name] => value
                                        )

                                )

                            [type] => value
                        )

                )

            [gender] => value
            [timezone] => value
            [locale] => value
            [verified] => value
            [updated_time] => value
        )

)

The problem is I only need the following keys:

[provider] => value

[info][image] => value

[credentials][token] => value

[raw][id] => value
[raw][name] => value
[raw][link] => value

How can I merge/combine and output only those keys?

Was it helpful?

Solution

Suggested by Michael Berkowski in the above comments.

foreach ($response as $result) {

    $data = 
        array(
            'provider' => $result['provider'], 
            'image' => $result['info']['image'],
            'token' => $result['credentials']['token'],
            'id' => $result['raw']['id'],
            'name' => $result['raw']['name'],
            'link' => $result['raw']['link'],
        );

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top