php object to array

How to convert this object to array?

I am using geocoder-php/google-maps-provider php-http/guzzle6-adapter php-http/message to convert the city, state to lat/long. The result is shown below when I output with print_r

Need some help converting this to an array or walk me through the steps to collect the data from the result.

Geocoder\Model\AddressCollection Object
(
    [locations:Geocoder\Model\AddressCollection:private] => Array
        (
            [0] => Geocoder\Provider\GoogleMaps\Model\GoogleAddress Object
                (
                    [id:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => ChIJXYHEcBpN-IgRW6TZSPQKM7U
                    [locationType:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => APPROXIMATE
                    [resultType:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => Array
                        (
                            [0] => locality
                            [1] => political
                        )

                    [formattedAddress:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => Aiken, SC, USA
                    [streetAddress:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [intersection:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [political:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => United States
                    [colloquialArea:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [ward:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [neighborhood:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [premise:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [subpremise:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [naturalFeature:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [airport:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [park:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [pointOfInterest:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [establishment:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => 
                    [subLocalityLevels:Geocoder\Provider\GoogleMaps\Model\GoogleAddress:private] => Geocoder\Model\AdminLevelCollection Object
                        (
                            [adminLevels:Geocoder\Model\AdminLevelCollection:private] => Array
                                (
                                )

                        )

                    [coordinates:Geocoder\Model\Address:private] => Geocoder\Model\Coordinates Object
                        (
                            [latitude:Geocoder\Model\Coordinates:private] => 33.5604168
                            [longitude:Geocoder\Model\Coordinates:private] => -81.7195533
                        )

                    [bounds:Geocoder\Model\Address:private] => Geocoder\Model\Bounds Object
                        (
                            [south:Geocoder\Model\Bounds:private] => 33.471154
                            [west:Geocoder\Model\Bounds:private] => -81.7790329
                            [north:Geocoder\Model\Bounds:private] => 33.590592
                            [east:Geocoder\Model\Bounds:private] => -81.6720859
                        )

                    [streetNumber:Geocoder\Model\Address:private] => 
                    [streetName:Geocoder\Model\Address:private] => 
                    [subLocality:Geocoder\Model\Address:private] => 
                    [locality:Geocoder\Model\Address:private] => Aiken
                    [postalCode:Geocoder\Model\Address:private] => 
                    [adminLevels:Geocoder\Model\Address:private] => Geocoder\Model\AdminLevelCollection Object
                        (
                            [adminLevels:Geocoder\Model\AdminLevelCollection:private] => Array
                                (
                                    [1] => Geocoder\Model\AdminLevel Object
                                        (
                                            [level:Geocoder\Model\AdminLevel:private] => 1
                                            [name:Geocoder\Model\AdminLevel:private] => South Carolina
                                            [code:Geocoder\Model\AdminLevel:private] => SC
                                        )

                                    [2] => Geocoder\Model\AdminLevel Object
                                        (
                                            [level:Geocoder\Model\AdminLevel:private] => 2
                                            [name:Geocoder\Model\AdminLevel:private] => Aiken County
                                            [code:Geocoder\Model\AdminLevel:private] => Aiken County
                                        )

                                )

                        )

                    [country:Geocoder\Model\Address:private] => Geocoder\Model\Country Object
                        (
                            [name:Geocoder\Model\Country:private] => United States
                            [code:Geocoder\Model\Country:private] => US
                        )

                    [timezone:Geocoder\Model\Address:private] => 
                    [providedBy:Geocoder\Model\Address:private] => google_maps
                )

        )

)

Open in new window

LVL 7
Robert SaylorSenior DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
To convert an object to an array just cast it
(array)$obj

Open in new window

Example
<?php
$obj = new stdClass;
$obj->name = 'Bob';
$obj->email='bob@domain.com';

$arr = (array)$obj;
echo "<pre>" . print_r($arr, true) . "</pre>";

Open in new window

But I don't think this is what you are after.
or walk me through the steps to collect the data from the result.
What do you want to get? The API seems quite extensive - if you tell us what information you want to extract we can take it from there
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Robert SaylorSenior DeveloperAuthor Commented:
This is what I want to extract. I have used stdClass before but this one if much different then I am use to.

                    [coordinates:Geocoder\Model\Address:private] => Geocoder\Model\Coordinates Object
                        (
                            [latitude:Geocoder\Model\Coordinates:private] => 33.5604168
                            [longitude:Geocoder\Model\Coordinates:private] => -81.7195533
                        )
0
gr8gonzoConsultantCommented:
I don't understand why you're trying to convert it to an array. The data already exists in your object. Are you unsure of how to access the data or are there specific fields that you're trying to get to?

If you're unsure of how to work with objects in PHP, check out my intro article on it:

https://www.experts-exchange.com/articles/2626/Beginning-Object-Oriented-Programming-in-PHP.html
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

gr8gonzoConsultantCommented:
No reason for deletion?
2
Robert SaylorSenior DeveloperAuthor Commented:
no solution given and I have retracted my question.
0
Julian HansenCommented:
Technically a solution was given. The question was how to convert a PHP object to an array - the answer is cast it to an array with (array).

In answering the question, though, we tried to determine what the use case was as the above was not really necessary given the data was available in the object.
0
Robert SaylorSenior DeveloperAuthor Commented:
This did work for part of the return object but due to the complex of the object I have went another direction.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.